home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-CPlus / cp-init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-18  |  128.5 KB  |  4,174 lines  |  [TEXT/MPS ]

  1. /* Handle initialization things in C++.
  2.    Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* High-level class interface. */
  23.  
  24. #include "config.h"
  25. #include "tree.h"
  26. #include "rtl.h"
  27. #include "cp-tree.h"
  28. #include "flags.h"
  29.  
  30. #define NULL 0
  31.  
  32. /* In C++, structures with well-defined constructors are initialized by
  33.    those constructors, unasked.  CURRENT_BASE_INIT_LIST
  34.    holds a list of stmts for a BASE_INIT term in the grammar.
  35.    This list has one element for each base class which must be
  36.    initialized.  The list elements are [basename, init], with
  37.    type basetype.  This allows the possibly anachronistic form
  38.    (assuming d : a, b, c) "d (int a) : c(a+5), b (a-4), a (a+3)"
  39.    where each successive term can be handed down the constructor
  40.    line.  Perhaps this was not intended.  */
  41. tree current_base_init_list, current_member_init_list;
  42.  
  43. void emit_base_init ();
  44. void check_base_init ();
  45. static void expand_aggr_vbase_init ();
  46. void expand_member_init ();
  47. void expand_aggr_init ();
  48.  
  49. static void expand_aggr_init_1 ();
  50. static void expand_recursive_init_1 ();
  51. static void expand_recursive_init ();
  52. tree expand_vec_init ();
  53. tree build_vec_delete ();
  54.  
  55. static void add_friend (), add_friends ();
  56.  
  57. int is_aggr_typedef ();
  58. /* Cache _builtin_new and _builtin_delete exprs.  */
  59. static tree BIN, BID;
  60.  
  61. #ifdef SOS
  62. tree get_linktable_name (), get_dtable_name (), get_sos_dtable ();
  63. static tree __sosFindCode, __sosLookup, __sosImport;
  64. static tree build_dynamic_new ();
  65. #endif
  66. static tree minus_one;
  67.  
  68. /* Set up local variable for this file.  MUST BE CALLED AFTER
  69.    INIT_DECL_PROCESSING.  */
  70.  
  71. tree BI_header_type, BI_header_size;
  72.  
  73. void init_init_processing ()
  74. {
  75.   tree op_id;
  76.   tree fields[2];
  77.  
  78.   /* Define implicit `operator new' and `operator delete' functions.  */
  79.   BIN = default_conversion (TREE_VALUE (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) NEW_EXPR])));
  80.   TREE_USED (TREE_OPERAND (BIN, 0)) = 0;
  81.   BID = default_conversion (TREE_VALUE (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) DELETE_EXPR])));
  82.   TREE_USED (TREE_OPERAND (BID, 0)) = 0;
  83.   minus_one = build_int_2 (-1, -1);
  84.  
  85.   op_id = ansi_opname[(int) NEW_EXPR];
  86.   IDENTIFIER_GLOBAL_VALUE (op_id) = BIN;
  87.   op_id = ansi_opname[(int) DELETE_EXPR];
  88.   IDENTIFIER_GLOBAL_VALUE (op_id) = BID;
  89.  
  90. #ifdef SOS
  91.   if (flag_all_virtual == 2)
  92.     {
  93.       __sosFindCode = default_conversion (lookup_name (get_identifier ("sosFindCode"), 0));
  94.       __sosLookup = default_conversion (lookup_name (get_identifier ("sosLookup"), 0));
  95.       __sosImport = default_conversion (lookup_name (get_identifier ("sosImport"), 0));
  96.     }
  97. #endif
  98.  
  99.   /* Define the structure that holds header information for
  100.      arrays allocated via operator new.  */
  101.   BI_header_type = make_lang_type (RECORD_TYPE);
  102.   fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("nelts"),
  103.                      sizetype);
  104.   fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr_2comp"),
  105.                      ptr_type_node);
  106.   finish_builtin_type (BI_header_type, "__new_cookie", fields, 1, double_type_node);
  107.   BI_header_size = size_in_bytes (BI_header_type);
  108. }
  109.  
  110. /* Recursive subroutine of emit_base_init.  For main type T,
  111.    recursively initialize the vfields of the base type PARENT.
  112.    RECURSE is non-zero when this function is being called
  113.    recursively.  */
  114.  
  115. static void
  116. init_vfields (t, parent, recurse)
  117.      tree t, parent;
  118.      int recurse;
  119. {
  120.   tree vfields;
  121.  
  122.   /* Initialize all the virtual function table fields that
  123.      do not come from virtual base classes.  */
  124.   vfields = CLASSTYPE_VFIELDS (parent);
  125.   while (vfields)
  126.     {
  127.       tree basetype = VF_DERIVED_VALUE (vfields)
  128.     ? TYPE_MAIN_VARIANT (VF_DERIVED_VALUE (vfields))
  129.       : VF_BASETYPE_VALUE (vfields);
  130.  
  131.       /* If the vtable installed by the constructor was not
  132.      the right one, fix that here.  */
  133.       if (TREE_ADDRESSABLE (vfields)
  134.       && CLASSTYPE_NEEDS_VIRTUAL_REINIT (basetype)
  135.       && (recurse > 0
  136.           || TYPE_HAS_CONSTRUCTOR (basetype)
  137.           /* BASE_INIT_LIST has already initialized the immediate basetypes.  */
  138.           || get_base_distance (basetype, t, 0, 0) > 1))
  139.     {
  140.       tree binfo = binfo_value (basetype, t, 0);
  141.       if ((recurse != 0 && (binfo != binfo_value (basetype, parent, 0)))
  142.           || (recurse == 0
  143.           && BINFO_VTABLE (binfo) != TYPE_BINFO_VTABLE (basetype)))
  144.         {
  145.           tree ptr = convert_pointer_to (binfo, current_class_decl);
  146.           expand_expr_stmt (build_virtual_init (TYPE_BINFO (t), binfo, ptr));
  147.         }
  148.       init_vfields (t, basetype, recurse+1);
  149.     }
  150.       vfields = TREE_CHAIN (vfields);
  151.     }
  152. }
  153.  
  154. /* Perform whatever initialization have yet to be done on the
  155.    base class of the class variable.  These actions are in
  156.    the global variable CURRENT_BASE_INIT_LIST.  Such an
  157.    action could be NULL_TREE, meaning that the user has explicitly
  158.    called the base class constructor with no arguments.
  159.  
  160.    If there is a need for a call to a constructor, we
  161.    must surround that call with a pushlevel/poplevel pair,
  162.    since we are technically at the PARM level of scope.
  163.  
  164.    Argument IMMEDIATELY, if zero, forces a new sequence to be generated
  165.    to contain these new insns, so it can be emitted later.  This sequence
  166.    is saved in the global variable BASE_INIT_INSNS.  Otherwise, the insns
  167.    are emitted into the current sequence.
  168.  
  169.    Note that emit_base_init does *not* initialize virtual
  170.    base classes.  That is done specially, elsewhere.  */
  171.    
  172. void
  173. emit_base_init (t, immediately)
  174.      tree t;
  175.      int immediately;
  176. {
  177.   extern tree in_charge_identifier;
  178.  
  179.   tree member, decl, vbases;
  180.   tree init_list;
  181.   int pass, start;
  182.   tree t_binfo = TYPE_BINFO (t);
  183.   tree binfos = BINFO_BASETYPES (t_binfo);
  184.   int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  185.   tree fields_to_unmark = NULL_TREE;
  186.  
  187.   if (! immediately)
  188.     {
  189.       do_pending_stack_adjust ();
  190.       start_sequence ();
  191.     }
  192.  
  193.   if (write_symbols == NO_DEBUG)
  194.     /* As a matter of principle, `start_sequence' should do this.  */
  195.     emit_note (0, -1);
  196.   else
  197.     /* Always emit a line number note so we can step into constructors.  */
  198.     emit_line_note_force (DECL_SOURCE_FILE (current_function_decl),
  199.               DECL_SOURCE_LINE (current_function_decl));
  200.  
  201.   /* In this case, we always need IN_CHARGE_NODE, because we have
  202.      to know whether to deallocate or not before exiting.  */
  203.   if (flag_handle_exceptions == 2
  204.       && lookup_name (in_charge_identifier, 0) == NULL_TREE)
  205.     {
  206.       tree in_charge_node = pushdecl (build_decl (VAR_DECL, in_charge_identifier,
  207.                           integer_type_node));
  208.       store_init_value (in_charge_node, build (EQ_EXPR, integer_type_node,
  209.                            current_class_decl,
  210.                            integer_zero_node));
  211.       expand_decl (in_charge_node);
  212.       expand_decl_init (in_charge_node);
  213.     }
  214.  
  215.   start = ! TYPE_USES_VIRTUAL_BASECLASSES (t);
  216.   for (pass = start; pass < 2; pass++)
  217.     {
  218.       tree vbase_init_list = NULL_TREE;
  219.  
  220.       for (init_list = current_base_init_list; init_list;
  221.        init_list = TREE_CHAIN (init_list))
  222.     {
  223.       tree basename = TREE_PURPOSE (init_list);
  224.       tree binfo;
  225.       tree init = TREE_VALUE (init_list);
  226.  
  227.       if (basename == NULL_TREE)
  228.         {
  229.           /* Initializer for single base class.  Must not
  230.          use multiple inheritance or this is ambiguous.  */
  231.           switch (n_baseclasses)
  232.         {
  233.         case 0:
  234.           error ("type `%s' does not have a base class to initialize",
  235.              IDENTIFIER_POINTER (current_class_name));
  236.           return;
  237.         case 1:
  238.           break;
  239.         default:
  240.           error ("unnamed initializer ambiguous for type `%s' which uses multiple inheritance", IDENTIFIER_POINTER (current_class_name));
  241.           return;
  242.         }
  243.           binfo = TREE_VEC_ELT (binfos, 0);
  244.         }
  245.       else if (is_aggr_typedef (basename, 1))
  246.         {
  247.           binfo = binfo_or_else (IDENTIFIER_TYPE_VALUE (basename), t);
  248.           if (binfo == NULL_TREE)
  249.         continue;
  250.  
  251.           /* Virtual base classes are special cases.  Their initializers
  252.          are recorded with this constructor, and they are used when
  253.          this constructor is the top-level constructor called.  */
  254.           if (! TREE_VIA_VIRTUAL (binfo))
  255.         {
  256.           /* Otherwise, if it is not an immediate base class, complain.  */
  257.           for (i = n_baseclasses-1; i >= 0; i--)
  258.             if (BINFO_TYPE (binfo) == BINFO_TYPE (TREE_VEC_ELT (binfos, i)))
  259.               break;
  260.           if (i < 0)
  261.             {
  262.               error ("type `%s' is not an immediate base class of type `%s'",
  263.                  IDENTIFIER_POINTER (basename),
  264.                  IDENTIFIER_POINTER (current_class_name));
  265.               continue;
  266.             }
  267.         }
  268.         }
  269.       else
  270.         continue;
  271.  
  272.       /* The base initialization list goes up to the first
  273.          base class which can actually use it.  */
  274.  
  275.       if (pass == start)
  276.         {
  277.           char *msgp = (! TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (binfo)))
  278.         ? "cannot pass initialization up to class `%s'" : 0;
  279.  
  280.           while (! TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (binfo))
  281.              && BINFO_BASETYPES (binfo) != NULL_TREE
  282.              && TREE_VEC_LENGTH (BINFO_BASETYPES (binfo)) == 1)
  283.         {
  284.           /* ?? This should be fixed in RENO by forcing
  285.              default constructors to exist.  */
  286.           SET_BINFO_BASEINIT_MARKED (binfo);
  287.           binfo = BINFO_BASETYPE (binfo, 0);
  288.         }
  289.  
  290.           if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (binfo)))
  291.         {
  292.           if (msgp)
  293.             {
  294.               if (pedantic)
  295.             error_with_aggr_type (binfo, msgp);
  296.               else
  297.             msgp = 0;
  298.             }
  299.         }
  300.           else
  301.         {
  302.           msgp = "no constructor found for initialization of `%s'";
  303.           error (msgp, IDENTIFIER_POINTER (basename));
  304.         }
  305.  
  306.           if (BINFO_BASEINIT_MARKED (binfo))
  307.         {
  308.           msgp = "class `%s' initializer already specified";
  309.           error (msgp, IDENTIFIER_POINTER (basename));
  310.         }
  311.           if (msgp)
  312.         continue;
  313.  
  314.           SET_BINFO_BASEINIT_MARKED (binfo);
  315.           if (TREE_VIA_VIRTUAL (binfo))
  316.         {
  317.           vbase_init_list = tree_cons (init, BINFO_TYPE (binfo),
  318.                            vbase_init_list);
  319.           continue;
  320.         }
  321.           if (pass == 0)
  322.         continue;
  323.         }
  324.       else if (TREE_VIA_VIRTUAL (binfo))
  325.         continue;
  326.  
  327.       member = convert_pointer_to (binfo, current_class_decl);
  328.       expand_aggr_init_1 (t_binfo, 0,
  329.                   build_indirect_ref (member, 0), init,
  330.                   BINFO_OFFSET_ZEROP (binfo),
  331.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  332.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (binfo)))
  333.         {
  334.           cplus_expand_start_try (1);
  335.           push_exception_cleanup (member);
  336.         }
  337.     }
  338.  
  339.       if (pass == 0)
  340.     {
  341.       tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl));
  342.       tree vbases;
  343.  
  344.       if (DECL_NAME (current_function_decl) == NULL_TREE
  345.           && TREE_CHAIN (first_arg) != NULL_TREE)
  346.         {
  347.           /* If there are virtual baseclasses without initialization
  348.          specified, and this is a default X(X&) constructor,
  349.          build the initialization list so that each virtual baseclass
  350.          of the new object is initialized from the virtual baseclass
  351.          of the incoming arg.  */
  352.           tree init_arg = build_unary_op (ADDR_EXPR, TREE_CHAIN (first_arg), 0);
  353.           for (vbases = CLASSTYPE_VBASECLASSES (t);
  354.            vbases; vbases = TREE_CHAIN (vbases))
  355.         {
  356.           if (BINFO_BASEINIT_MARKED (vbases) == 0)
  357.             {
  358.               member = convert_pointer_to (vbases, init_arg);
  359.               if (member == init_arg)
  360.             member = TREE_CHAIN (first_arg);
  361.               else
  362.             TREE_TYPE (member) = build_reference_type (BINFO_TYPE (vbases));
  363.               vbase_init_list = tree_cons (convert_from_reference (member),
  364.                            vbases, vbase_init_list);
  365.               SET_BINFO_BASEINIT_MARKED (vbases);
  366.             }
  367.         }
  368.         }
  369.       expand_start_cond (first_arg, 0);
  370.       expand_aggr_vbase_init (t_binfo, C_C_D, current_class_decl,
  371.                   vbase_init_list);
  372.       expand_expr_stmt (build_vbase_vtables_init (t_binfo, t_binfo,
  373.                               C_C_D, current_class_decl, 1));
  374.       expand_end_cond ();
  375.     }
  376.     }
  377.   current_base_init_list = NULL_TREE;
  378.  
  379.   /* Now, perform default initialization of all base classes which
  380.      have not yet been initialized, and unmark baseclasses which
  381.      have been initialized.  */
  382.   for (i = 0; i < n_baseclasses; i++)
  383.     {
  384.       tree base = current_class_decl;
  385.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  386.  
  387.       if (TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (base_binfo)))
  388.     {
  389.       if (! TREE_VIA_VIRTUAL (base_binfo)
  390.           && ! BINFO_BASEINIT_MARKED (base_binfo))
  391.         {
  392.           tree ref;
  393.  
  394.           if (BINFO_OFFSET_ZEROP (base_binfo))
  395.         base = build1 (NOP_EXPR,
  396.                    TYPE_POINTER_TO (BINFO_TYPE (base_binfo)),
  397.                    current_class_decl);
  398.           else
  399.         base = build (PLUS_EXPR,
  400.                   TYPE_POINTER_TO (BINFO_TYPE (base_binfo)),
  401.                   current_class_decl, BINFO_OFFSET (base_binfo));
  402.  
  403.           ref = build_indirect_ref (base, 0);
  404.           expand_aggr_init_1 (t_binfo, 0, ref, NULL_TREE,
  405.                   BINFO_OFFSET_ZEROP (base_binfo),
  406.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  407.           if (flag_handle_exceptions == 2
  408.           && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
  409.         {
  410.           cplus_expand_start_try (1);
  411.           push_exception_cleanup (base);
  412.         }
  413.         }
  414.     }
  415.       CLEAR_BINFO_BASEINIT_MARKED (base_binfo);
  416.     }
  417.   for (vbases = CLASSTYPE_VBASECLASSES (t); vbases; vbases = TREE_CHAIN (vbases))
  418.     CLEAR_BINFO_BASEINIT_MARKED (vbases);
  419.  
  420.   /* Initialize all the virtual function table fields that
  421.      do not come from virtual base classes.  */
  422.   init_vfields (t, t, 0);
  423.  
  424.   if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (t)
  425. #ifdef SOS
  426.        || TYPE_DYNAMIC (t)
  427. #endif
  428.        )
  429.     expand_expr_stmt (build_virtual_init (TYPE_BINFO (t), t,
  430.                       current_class_decl));
  431.  
  432.   /* Members we through expand_member_init.  We initialize all the members
  433.      needing initialization that did not get it so far.  */
  434.   for (; current_member_init_list;
  435.        current_member_init_list = TREE_CHAIN (current_member_init_list))
  436.     {
  437.       tree name = TREE_PURPOSE (current_member_init_list);
  438.       tree init = TREE_VALUE (current_member_init_list);
  439.       tree field = (TREE_CODE (name) == COMPONENT_REF
  440.             ? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
  441.       tree type;
  442.       
  443.       /* If one member shadows another, get the outermost one.  */
  444.       if (TREE_CODE (field) == TREE_LIST)
  445.     {
  446.       field = TREE_VALUE (field);
  447.       if (decl_type_context (field) != current_class_type)
  448.         error ("field `%s' not in immediate context");
  449.     }
  450.  
  451.       type = TREE_TYPE (field);
  452.  
  453.       if (TREE_STATIC (field))
  454.     {
  455.       error_with_aggr_type (DECL_FIELD_CONTEXT (field),
  456.                 "field `%s::%s' is static; only point of initialization is its declaration", IDENTIFIER_POINTER (name));
  457.       continue;
  458.     }
  459.  
  460.       if (DECL_NAME (field))
  461.     {
  462.       if (TREE_HAS_CONSTRUCTOR (field))
  463.         error ("multiple initializations given for member `%s'",
  464.            IDENTIFIER_POINTER (DECL_NAME (field)));
  465.     }
  466.  
  467.       /* Mark this node as having been initialized.  */
  468.       TREE_HAS_CONSTRUCTOR (field) = 1;
  469.       if (DECL_FIELD_CONTEXT (field) != t)
  470.     fields_to_unmark = tree_cons (NULL_TREE, field, fields_to_unmark);
  471.  
  472.       if (TREE_CODE (name) == COMPONENT_REF)
  473.     {
  474.       /* Initialization of anonymous union.  */
  475.       expand_assignment (name, init, 0, 0);
  476.       continue;
  477.     }
  478.       decl = build_component_ref (C_C_D, name, 0, 1);
  479.  
  480.       if (TYPE_NEEDS_CONSTRUCTING (type))
  481.     {
  482.       if (TREE_CODE (type) == ARRAY_TYPE
  483.           && TREE_CHAIN (init) == NULL_TREE
  484.           && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
  485.         {
  486.           /* Initialization of one array from another.  */
  487.           expand_vec_init (TREE_OPERAND (decl, 1), decl,
  488.                    array_type_nelts (type), TREE_VALUE (init), 1);
  489.         }
  490.       else
  491.         expand_aggr_init (decl, init, 0);
  492.     }
  493.       else
  494.     {
  495.       if (init == NULL_TREE)
  496.         {
  497.           error ("types without constructors must have complete initializers");
  498.           init = error_mark_node;
  499.         }
  500.       else if (TREE_CHAIN (init))
  501.         {
  502.           warning ("initializer list treated as compound expression");
  503.           init = build_compound_expr (init);
  504.         }
  505.       else
  506.         init = TREE_VALUE (init);
  507.  
  508.       expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
  509.     }
  510.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (type))
  511.     {
  512.       cplus_expand_start_try (1);
  513.       push_exception_cleanup (build_unary_op (ADDR_EXPR, decl, 0));
  514.     }
  515.     }
  516.  
  517.   for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
  518.     {
  519.       /* All we care about is this unique member.  It contains
  520.      all the information we need to know, and that right early.  */
  521.       tree type = TREE_TYPE (member);
  522.       tree init = TREE_HAS_CONSTRUCTOR (member)
  523.     ? error_mark_node : DECL_INITIAL (member);
  524.  
  525.       /* Unmark this field.  If it is from an anonymous union,
  526.          then unmark the field recursively.  */
  527.       TREE_HAS_CONSTRUCTOR (member) = 0;
  528.       if (TREE_ANON_UNION_ELEM (member))
  529.     emit_base_init (TREE_TYPE (member), 1);
  530.  
  531.       /* Member had explicit initializer.  */
  532.       if (init == error_mark_node)
  533.     continue;
  534.  
  535.       if (TREE_CODE (member) != FIELD_DECL)
  536.     continue;
  537.  
  538.       if (type == error_mark_node)
  539.     continue;
  540.  
  541.       if (TYPE_NEEDS_CONSTRUCTING (type))
  542.     {
  543.       if (init)
  544.         init = build_tree_list (NULL_TREE, init);
  545.       decl = build_component_ref (C_C_D, DECL_NAME (member), 0, 0);
  546.       expand_aggr_init (decl, init, 0);
  547.     }
  548.       else
  549.     {
  550.       if (init)
  551.         {
  552.           decl = build_component_ref (C_C_D, DECL_NAME (member), 0, 0);
  553.           expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
  554.         }
  555.       else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE)
  556.         warning ("uninitialized reference member `%s'",
  557.              IDENTIFIER_POINTER (DECL_NAME (member)));
  558.     }
  559.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (type))
  560.     {
  561.       cplus_expand_start_try (1);
  562.       push_exception_cleanup (build_unary_op (ADDR_EXPR, decl, 0));
  563.     }
  564.     }
  565.   /* Unmark fields which are initialized for the base class.  */
  566.   while (fields_to_unmark)
  567.     {
  568.       TREE_HAS_CONSTRUCTOR (TREE_VALUE (fields_to_unmark)) = 0;
  569.       fields_to_unmark = TREE_CHAIN (fields_to_unmark);
  570.     }
  571.  
  572.   /* It is possible for the initializers to need cleanups.
  573.      Expand those cleanups now that all the initialization
  574.      has been done.  */
  575.   expand_cleanups_to (NULL_TREE);
  576.  
  577.   if (! immediately)
  578.     {
  579.       extern rtx base_init_insns;
  580.  
  581.       do_pending_stack_adjust ();
  582.       my_friendly_assert (base_init_insns == 0, 207);
  583.       base_init_insns = get_insns ();
  584.       end_sequence ();
  585.     }
  586.  
  587.   /* All the implicit try blocks we built up will be zapped
  588.      when we come to a real binding contour boundary.  */
  589. }
  590.  
  591. /* Check that all fields are properly initialized after
  592.    an assignment to `this'.  */
  593. void
  594. check_base_init (t)
  595.      tree t;
  596. {
  597.   tree member;
  598.   for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
  599.     if (DECL_NAME (member) && TREE_USED (member))
  600.       error ("field `%s' used before initialized (after assignment to `this')",
  601.          IDENTIFIER_POINTER (DECL_NAME (member)));
  602. }
  603.  
  604. /* This code sets up the virtual function tables appropriate for
  605.    the pointer DECL.  It is a one-ply initialization.
  606.  
  607.    BINFO is the exact type that DECL is supposed to be.  In
  608.    multiple inheritance, this might mean "C's A" if C : A, B.  */
  609. tree
  610. build_virtual_init (main_binfo, binfo, decl)
  611.      tree main_binfo, binfo;
  612.      tree decl;
  613. {
  614.   tree type;
  615.   tree vtbl, vtbl_ptr;
  616.   tree vtype;
  617.  
  618.   if (TREE_CODE (binfo) == TREE_VEC)
  619.     type = BINFO_TYPE (binfo);
  620.   else if (TREE_CODE (binfo) == RECORD_TYPE)
  621.     {
  622.       type = binfo;
  623.       binfo = TYPE_BINFO (type);
  624.     }
  625.   else
  626.     my_friendly_abort (46);
  627.  
  628.   vtype = DECL_CONTEXT (CLASSTYPE_VFIELD (type));
  629. #if 0
  630.   /* This code suggests that it's time to rewrite how we handle
  631.      replicated baseclasses in G++.  */
  632.   if (get_base_distance (vtype, TREE_TYPE (TREE_TYPE (decl)), 0, 0) == -2)
  633.     {
  634.       tree binfos = TYPE_BINFO_BASETYPES (TREE_TYPE (TREE_TYPE (decl)));
  635.       int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  636.       tree result = NULL_TREE;
  637.  
  638.       for (i = n_baselinks-1; i >= 0; i--)
  639.     {
  640.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  641.       tree this_decl;
  642.  
  643.       if (get_base_distance (vtype, BINFO_TYPE (base_binfo), 0, 0) == -1)
  644.         continue;
  645.  
  646.       if (TREE_VIA_VIRTUAL (base_binfo))
  647.         this_decl = build_vbase_pointer (build_indirect_ref (decl), BINFO_TYPE (base_binfo));
  648.       else if (BINFO_OFFSET_ZEROP (base_binfo))
  649.         this_decl = build1 (NOP_EXPR, TYPE_POINTER_TO (BINFO_TYPE (base_binfo)),
  650.                 decl);
  651.       else
  652.         this_decl = build (PLUS_EXPR, TYPE_POINTER_TO (BINFO_TYPE (base_binfo)),
  653.                    decl, BINFO_OFFSET (base_binfo));
  654.       result = tree_cons (NULL_TREE, build_virtual_init (main_binfo, base_binfo, this_decl), result);
  655.     }
  656.       return build_compound_expr (result);
  657.     }
  658. #endif
  659.  
  660. #ifdef SOS
  661.   if (TYPE_DYNAMIC (type))
  662.     vtbl = build1 (NOP_EXPR, ptr_type_node, lookup_name (get_identifier (AUTO_VTABLE_NAME), 0));
  663.   else
  664. #endif
  665.     {
  666. #if 1
  667.       vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (type)),
  668.                     BINFO_TYPE (main_binfo), 0));
  669. #else
  670.       my_friendly_assert (BINFO_TYPE (main_binfo) == BINFO_TYPE (binfo), 208);
  671.       vtbl = BINFO_VTABLE (main_binfo);
  672. #endif /* 1 */
  673.       assemble_external (vtbl);
  674.       TREE_USED (vtbl) = 1;
  675.       vtbl = build1 (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (vtbl)), vtbl);
  676.     }
  677.   decl = convert_pointer_to (vtype, decl);
  678.   vtbl_ptr = build_vfield_ref (build_indirect_ref (decl, 0), vtype);
  679.   if (vtbl_ptr == error_mark_node)
  680.     return error_mark_node;
  681.  
  682.   /* Have to convert VTBL since array sizes may be different.  */
  683.   return build_modify_expr (vtbl_ptr, NOP_EXPR,
  684.                 convert (TREE_TYPE (vtbl_ptr), vtbl));
  685. }
  686.  
  687. /* Subroutine of `expand_aggr_vbase_init'.
  688.    BINFO is the binfo of the type that is being initialized.
  689.    INIT_LIST is the list of initializers for the virtual baseclass.  */
  690. static void
  691. expand_aggr_vbase_init_1 (binfo, exp, addr, init_list)
  692.      tree binfo, exp, addr, init_list;
  693. {
  694.   tree init = value_member (BINFO_TYPE (binfo), init_list);
  695.   tree ref = build_indirect_ref (addr, 0);
  696.   if (init)
  697.     init = TREE_PURPOSE (init);
  698.   /* Call constructors, but don't set up vtables.  */
  699.   expand_aggr_init_1 (binfo, exp, ref, init, 0,
  700.               LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN|LOOKUP_SPECULATIVELY);
  701.   CLEAR_BINFO_VBASE_INIT_MARKED (binfo);
  702. }
  703.  
  704. /* Initialize this object's virtual base class pointers.  This must be
  705.    done only at the top-level of the object being constructed.
  706.  
  707.    INIT_LIST is list of initialization for constructor to perform.  */
  708. static void
  709. expand_aggr_vbase_init (binfo, exp, addr, init_list)
  710.      tree binfo;
  711.      tree exp;
  712.      tree addr;
  713.      tree init_list;
  714. {
  715.   tree type = BINFO_TYPE (binfo);
  716.  
  717.   if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  718.     {
  719.       tree result = init_vbase_pointers (type, addr);
  720.       tree vbases;
  721.  
  722.       if (result)
  723.     expand_expr_stmt (build_compound_expr (result));
  724.  
  725.       /* Mark everything as having an initializer
  726.      (either explicit or default).  */
  727.       for (vbases = CLASSTYPE_VBASECLASSES (type);
  728.        vbases; vbases = TREE_CHAIN (vbases))
  729.     SET_BINFO_VBASE_INIT_MARKED (vbases);
  730.  
  731.       /* First, initialize baseclasses which could be baseclasses
  732.      for other virtual baseclasses.  */
  733.       for (vbases = CLASSTYPE_VBASECLASSES (type);
  734.        vbases; vbases = TREE_CHAIN (vbases))
  735.     /* Don't initialize twice.  */
  736.     if (BINFO_VBASE_INIT_MARKED (vbases))
  737.       {
  738.         tree tmp = result;
  739.  
  740.         while (BINFO_TYPE (vbases) != BINFO_TYPE (TREE_PURPOSE (tmp)))
  741.           tmp = TREE_CHAIN (tmp);
  742.         expand_aggr_vbase_init_1 (vbases, exp,
  743.                       TREE_OPERAND (TREE_VALUE (tmp), 0),
  744.                       init_list);
  745.       }
  746.  
  747.       /* Now initialize the baseclasses which don't have virtual baseclasses.  */
  748.       for (; result; result = TREE_CHAIN (result))
  749.     /* Don't initialize twice.  */
  750.     if (BINFO_VBASE_INIT_MARKED (TREE_PURPOSE (result)))
  751.       {
  752.         my_friendly_abort (47);
  753.         expand_aggr_vbase_init_1 (TREE_PURPOSE (result), exp,
  754.                       TREE_OPERAND (TREE_VALUE (result), 0),
  755.                       init_list);
  756.       }
  757.     }
  758. }
  759.  
  760. /* Subroutine to perform parser actions for member initialization.
  761.    S_ID is the scoped identifier.
  762.    NAME is the name of the member.
  763.    INIT is the initializer, or `void_type_node' if none.  */
  764. void
  765. do_member_init (s_id, name, init)
  766.      tree s_id, name, init;
  767. {
  768.   tree binfo, base;
  769.  
  770.   if (current_class_type == NULL_TREE
  771.       || ! is_aggr_typedef (s_id, 1))
  772.     return;
  773.   binfo = get_binfo (IDENTIFIER_TYPE_VALUE (s_id),
  774.               current_class_type, 1);
  775.   if (binfo == error_mark_node)
  776.     return;
  777.   if (binfo == 0)
  778.     {
  779.       error_not_base_type (IDENTIFIER_TYPE_VALUE (s_id), current_class_type);
  780.       return;
  781.     }
  782.  
  783.   base = convert_pointer_to (binfo, current_class_decl);
  784.   expand_member_init (build_indirect_ref (base), name, init);
  785. }
  786.  
  787. /* Function to give error message if member initialization specification
  788.    is erroneous.  FIELD is the member we decided to initialize.
  789.    TYPE is the type for which the initialization is being performed.
  790.    FIELD must be a member of TYPE, or the base type from which FIELD
  791.    comes must not need a constructor.
  792.    
  793.    MEMBER_NAME is the name of the member.  */
  794.  
  795. static int
  796. member_init_ok_or_else (field, type, member_name)
  797.      tree field;
  798.      tree type;
  799.      char *member_name;
  800. {
  801.   if (field == error_mark_node) return 0;
  802.   if (field == NULL_TREE)
  803.     {
  804.       error_with_aggr_type (type, "class `%s' does not have any field named `%s'",
  805.                 member_name);
  806.       return 0;
  807.     }
  808.   if (DECL_CONTEXT (field) != type
  809.       && TYPE_NEEDS_CONSTRUCTOR (DECL_CONTEXT (field)))
  810.     {
  811.       error ("member `%s' comes from base class needing constructor", member_name);
  812.       return 0;
  813.     }
  814.   return 1;
  815. }
  816.  
  817. /* If NAME is a viable field name for the aggregate DECL,
  818.    and PARMS is a viable parameter list, then expand an _EXPR
  819.    which describes this initialization.
  820.  
  821.    Note that we do not need to chase through the class's base classes
  822.    to look for NAME, because if it's in that list, it will be handled
  823.    by the constructor for that base class.
  824.  
  825.    We do not yet have a fixed-point finder to instantiate types
  826.    being fed to overloaded constructors.  If there is a unique
  827.    constructor, then argument types can be got from that one.
  828.  
  829.    If INIT is non-NULL, then it the initialization should
  830.    be placed in `current_base_init_list', where it will be processed
  831.    by `emit_base_init'.  */
  832. void
  833. expand_member_init (exp, name, init)
  834.      tree exp, name, init;
  835. {
  836.   extern tree ptr_type_node;    /* should be in tree.h */
  837.  
  838.   tree basetype = NULL_TREE, field;
  839.   tree parm;
  840.   tree rval, type;
  841.   tree actual_name;
  842.  
  843.   if (exp == NULL_TREE)
  844.     return;            /* complain about this later */
  845.  
  846.   type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
  847.  
  848.   if (name == NULL_TREE && IS_AGGR_TYPE (type))
  849.     switch (CLASSTYPE_N_BASECLASSES (type))
  850.       {
  851.       case 0:
  852.     error ("base class initializer specified, but no base class to initialize");
  853.     return;
  854.       case 1:
  855.     basetype = TYPE_BINFO_BASETYPE (type, 0);
  856.     break;
  857.       default:
  858.     error ("initializer for unnamed base class ambiguous");
  859.     error_with_aggr_type (type, "(type `%s' uses multiple inheritance)");
  860.     return;
  861.       }
  862.  
  863.   if (init)
  864.     {
  865.       /* The grammar should not allow fields which have names
  866.      that are TYPENAMEs.  Therefore, if the field has
  867.      a non-NULL TREE_TYPE, we may assume that this is an
  868.      attempt to initialize a base class member of the current
  869.      type.  Otherwise, it is an attempt to initialize a
  870.      member field.  */
  871.  
  872.       if (init == void_type_node)
  873.     init = NULL_TREE;
  874.  
  875.       if (name == NULL_TREE || IDENTIFIER_HAS_TYPE_VALUE (name))
  876.     {
  877.       tree base_init;
  878.  
  879.       if (name == NULL_TREE)
  880.         if (basetype)
  881.           name = TYPE_IDENTIFIER (basetype);
  882.         else
  883.           {
  884.         error ("no base class to initialize");
  885.         return;
  886.           }
  887.       else
  888.         {
  889.           basetype = IDENTIFIER_TYPE_VALUE (name);
  890.           if (basetype != type
  891.           && ! binfo_member (basetype, TYPE_BINFO (type))
  892.           && ! binfo_member (basetype, CLASSTYPE_VBASECLASSES (type)))
  893.         {
  894.           if (IDENTIFIER_CLASS_VALUE (name))
  895.             goto try_member;
  896.           if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  897.             error ("type `%s' is not an immediate or virtual basetype for `%s'",
  898.                IDENTIFIER_POINTER (name),
  899.                TYPE_NAME_STRING (type));
  900.           else
  901.             error ("type `%s' is not an immediate basetype for `%s'",
  902.                IDENTIFIER_POINTER (name),
  903.                TYPE_NAME_STRING (type));
  904.           return;
  905.         }
  906.         }
  907.  
  908.       if (purpose_member (name, current_base_init_list))
  909.         {
  910.           error ("base class `%s' already initialized",
  911.              IDENTIFIER_POINTER (name));
  912.           return;
  913.         }
  914.  
  915.       base_init = build_tree_list (name, init);
  916.       TREE_TYPE (base_init) = basetype;
  917.       current_base_init_list = chainon (current_base_init_list, base_init);
  918.     }
  919.       else
  920.     {
  921.       tree member_init;
  922.  
  923.     try_member:
  924.       field = lookup_field (type, name, 1, 0);
  925.  
  926.       if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name)))
  927.         return;
  928.  
  929.       if (purpose_member (name, current_member_init_list))
  930.         {
  931.           error ("field `%s' already initialized", IDENTIFIER_POINTER (name));
  932.           return;
  933.         }
  934.  
  935.       member_init = build_tree_list (name, init);
  936.       TREE_TYPE (member_init) = TREE_TYPE (field);
  937.       current_member_init_list = chainon (current_member_init_list, member_init);
  938.     }
  939.       return;
  940.     }
  941.   else if (name == NULL_TREE)
  942.     {
  943.       compiler_error ("expand_member_init: name == NULL_TREE");
  944.       return;
  945.     }
  946.  
  947.   basetype = type;
  948.   field = lookup_field (basetype, name, 0, 0);
  949.  
  950.   if (! member_init_ok_or_else (field, basetype, IDENTIFIER_POINTER (name)))
  951.     return;
  952.  
  953.   /* now see if there is a constructor for this type
  954.      which will take these args. */
  955.  
  956.   if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (field)))
  957.     {
  958.       tree parmtypes, fndecl;
  959.  
  960.       if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
  961.     {
  962.       /* just know that we've seen something for this node */
  963.       DECL_INITIAL (exp) = error_mark_node;
  964.       TREE_USED (exp) = 1;
  965.     }
  966.       type = TYPE_MAIN_VARIANT (TREE_TYPE (field));
  967.       actual_name = TYPE_IDENTIFIER (type);
  968.       parm = build_component_ref (exp, name, 0, 0);
  969.  
  970.       /* Now get to the constructor.  */
  971.       fndecl = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0);
  972.       /* Get past destructor, if any.  */
  973.       if (TYPE_HAS_DESTRUCTOR (type))
  974.     fndecl = DECL_CHAIN (fndecl);
  975.  
  976.       if (fndecl)
  977.     my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 209);
  978.  
  979.       /* If the field is unique, we can use the parameter
  980.      types to guide possible type instantiation.  */
  981.       if (DECL_CHAIN (fndecl) == NULL_TREE)
  982.     {
  983.       /* There was a confusion here between
  984.          FIELD and FNDECL.  The following code
  985.          should be correct, but abort is here
  986.          to make sure.  */
  987.       my_friendly_abort (48);
  988.       parmtypes = FUNCTION_ARG_CHAIN (fndecl);
  989.     }
  990.       else
  991.     {
  992.       parmtypes = NULL_TREE;
  993.       fndecl = NULL_TREE;
  994.     }
  995.  
  996.       init = convert_arguments (parm, parmtypes, NULL_TREE, fndecl, LOOKUP_NORMAL);
  997.       if (init == NULL_TREE || TREE_TYPE (init) != error_mark_node)
  998.     rval = build_method_call (NULL_TREE, actual_name, init, NULL_TREE, LOOKUP_NORMAL);
  999.       else
  1000.     return;
  1001.  
  1002.       if (rval != error_mark_node)
  1003.     {
  1004.       /* Now, fill in the first parm with our guy */
  1005.       TREE_VALUE (TREE_OPERAND (rval, 1))
  1006.         = build_unary_op (ADDR_EXPR, parm, 0);
  1007.       TREE_TYPE (rval) = ptr_type_node;
  1008.       TREE_SIDE_EFFECTS (rval) = 1;
  1009.     }
  1010.     }
  1011.   else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
  1012.     {
  1013.       parm = build_component_ref (exp, name, 0, 0);
  1014.       expand_aggr_init (parm, NULL_TREE, 0);
  1015.       rval = error_mark_node;
  1016.     }
  1017.  
  1018.   /* Now initialize the member.  It does not have to
  1019.      be of aggregate type to receive initialization.  */
  1020.   if (rval != error_mark_node)
  1021.     expand_expr_stmt (rval);
  1022. }
  1023.  
  1024. /* This is like `expand_member_init', only it stores one aggregate
  1025.    value into another.
  1026.  
  1027.    INIT comes in two flavors: it is either a value which
  1028.    is to be stored in EXP, or it is a parameter list
  1029.    to go to a constructor, which will operate on EXP.
  1030.    If `init' is a CONSTRUCTOR, then we emit a warning message,
  1031.    explaining that such initializations are illegal.
  1032.  
  1033.    ALIAS_THIS is nonzero iff we are initializing something which is
  1034.    essentially an alias for C_C_D.  In this case, the base constructor
  1035.    may move it on us, and we must keep track of such deviations.
  1036.  
  1037.    If INIT resolves to a CALL_EXPR which happens to return
  1038.    something of the type we are looking for, then we know
  1039.    that we can safely use that call to perform the
  1040.    initialization.
  1041.  
  1042.    The virtual function table pointer cannot be set up here, because
  1043.    we do not really know its type.
  1044.  
  1045.    Virtual baseclass pointers are also set up here.
  1046.  
  1047.    This never calls operator=().
  1048.  
  1049.    When initializing, nothing is CONST.
  1050.  
  1051.    A default copy constructor may have to be used to perform the
  1052.    initialization.
  1053.  
  1054.    A constructor or a conversion operator may have to be used to
  1055.    perform the initialization, but not both, as it would be ambiguous.
  1056.    */
  1057.  
  1058. void
  1059. expand_aggr_init (exp, init, alias_this)
  1060.      tree exp, init;
  1061.      int alias_this;
  1062. {
  1063.   tree type = TREE_TYPE (exp);
  1064.   int was_const = TREE_READONLY (exp);
  1065.  
  1066.   if (init == error_mark_node)
  1067.     return;
  1068.  
  1069.   TREE_READONLY (exp) = 0;
  1070.  
  1071.   if (TREE_CODE (type) == ARRAY_TYPE)
  1072.     {
  1073.       /* Must arrange to initialize each element of EXP
  1074.      from elements of INIT.  */
  1075.       int was_const_elts = TYPE_READONLY (TREE_TYPE (type));
  1076.       tree itype = init ? TREE_TYPE (init) : NULL_TREE;
  1077.       if (was_const_elts)
  1078.     {
  1079.       tree atype = build_cplus_array_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  1080.                            TYPE_DOMAIN (type));
  1081.       if (init && (TREE_TYPE (exp) == TREE_TYPE (init)))
  1082.         TREE_TYPE (init) = atype;
  1083.       TREE_TYPE (exp) = atype;
  1084.     }
  1085.       expand_vec_init (exp, exp, array_type_nelts (type), init,
  1086.                init && comptypes (TREE_TYPE (init), TREE_TYPE (exp), 1));
  1087.       TREE_READONLY (exp) = was_const;
  1088.       TREE_TYPE (exp) = type;
  1089.       if (init) TREE_TYPE (init) = itype;
  1090.       return;
  1091.     }
  1092.  
  1093.   if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
  1094.     /* just know that we've seen something for this node */
  1095.     TREE_USED (exp) = 1;
  1096.  
  1097.   /* If initializing from a GNU C CONSTRUCTOR, consider the elts in the
  1098.      constructor as parameters to an implicit GNU C++ constructor.  */
  1099.   if (init && TREE_CODE (init) == CONSTRUCTOR
  1100.       && TYPE_HAS_CONSTRUCTOR (type)
  1101.       && TREE_TYPE (init) == type)
  1102.     init = CONSTRUCTOR_ELTS (init);
  1103.   expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
  1104.               init, alias_this, LOOKUP_NORMAL);
  1105.   TREE_READONLY (exp) = was_const;
  1106. }
  1107.  
  1108. static void
  1109. expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags)
  1110.      tree binfo;
  1111.      tree true_exp, exp;
  1112.      tree type;
  1113.      tree init;
  1114.      int alias_this;
  1115.      int flags;
  1116. {
  1117.   /* It fails because there may not be a constructor which takes
  1118.      its own type as the first (or only parameter), but which does
  1119.      take other types via a conversion.  So, if the thing initializing
  1120.      the expression is a unit element of type X, first try X(X&),
  1121.      followed by initialization by X.  If neither of these work
  1122.      out, then look hard.  */
  1123.   tree rval;
  1124.   tree parms;
  1125.   int xxref_init_possible;
  1126.  
  1127.   if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
  1128.     {
  1129.       parms = init;
  1130.       if (parms) init = TREE_VALUE (parms);
  1131.     }
  1132.   else if (TREE_CODE (init) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (init))
  1133.     {
  1134.       convert_for_initialization (exp, type, init, 0, 0, 0, 0);
  1135.       expand_expr_stmt (TREE_OPERAND (init, 0));
  1136.       return;
  1137.     }
  1138.   else parms = build_tree_list (NULL_TREE, init);
  1139.  
  1140.   if (TYPE_HAS_INIT_REF (type)
  1141.       || init == NULL_TREE
  1142.       || TREE_CHAIN (parms) != NULL_TREE)
  1143.     xxref_init_possible = 0;
  1144.   else
  1145.     {
  1146.       xxref_init_possible = LOOKUP_SPECULATIVELY;
  1147.       flags &= ~LOOKUP_COMPLAIN;
  1148.     }
  1149.  
  1150.   if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  1151.     {
  1152.       if (true_exp == exp)
  1153.     parms = tree_cons (NULL_TREE, integer_one_node, parms);
  1154.       else
  1155.     parms = tree_cons (NULL_TREE, integer_zero_node, parms);
  1156.       flags |= LOOKUP_HAS_IN_CHARGE;
  1157.     }
  1158.  
  1159.   /* ARM $7.1.1: "[register] may be ignored and in most implementations
  1160.      it will be ignored if the address of the variable is taken."
  1161.      Since we're likely to do just that in the ctor call, clear this.  */
  1162.   DECL_REGISTER (exp) = 0;
  1163.  
  1164.   rval = build_method_call (exp, constructor_name (type),
  1165.                 parms, binfo, flags|xxref_init_possible);
  1166.   if (rval == NULL_TREE && xxref_init_possible)
  1167.     {
  1168.       /* It is an error to implement a default copy constructor if
  1169.      (see ARM 12.8 for details) ... one case being if another
  1170.      copy constructor already exists. */
  1171.       tree init_type = TREE_TYPE (init);
  1172.       if (TREE_CODE (init_type) == REFERENCE_TYPE)
  1173.     init_type = TREE_TYPE (init_type);
  1174.       if (TYPE_MAIN_VARIANT (init_type) == TYPE_MAIN_VARIANT (type)
  1175.       || (IS_AGGR_TYPE (init_type)
  1176.           && UNIQUELY_DERIVED_FROM_P (type, init_type)))
  1177.     {
  1178.       if (type == BINFO_TYPE (binfo)
  1179.           && TYPE_USES_VIRTUAL_BASECLASSES (type))
  1180.         {
  1181.           tree addr = build_unary_op (ADDR_EXPR, exp, 0);
  1182.           expand_aggr_vbase_init (binfo, exp, addr, NULL_TREE);
  1183.  
  1184.           expand_expr_stmt (build_vbase_vtables_init (binfo, binfo,
  1185.                               exp, addr, 1));
  1186.         }
  1187.       expand_expr_stmt (build_modify_expr (exp, INIT_EXPR, init));
  1188.       return;
  1189.     }
  1190.       else
  1191.     rval = build_method_call (exp, constructor_name (type), parms,
  1192.                   binfo, flags);
  1193.     }
  1194.  
  1195.   /* Private, protected, or otherwise unavailable.  */
  1196.   if (rval == error_mark_node && (flags&LOOKUP_COMPLAIN))
  1197.     error_with_aggr_type (binfo, "in base initialization for class `%s'");
  1198.   /* A valid initialization using constructor.  */
  1199.   else if (rval != error_mark_node && rval != NULL_TREE)
  1200.     {
  1201.       /* p. 222: if the base class assigns to `this', then that
  1202.      value is used in the derived class.  */
  1203.       if ((flag_this_is_variable & 1) && alias_this)
  1204.     {
  1205.       TREE_TYPE (rval) = TREE_TYPE (current_class_decl);
  1206.       expand_assignment (current_class_decl, rval, 0, 0);
  1207.     }
  1208.       else
  1209.     expand_expr_stmt (rval);
  1210.     }
  1211.   else if (parms && TREE_CHAIN (parms) == NULL_TREE)
  1212.     {
  1213.       /* If we are initializing one aggregate value
  1214.      from another, and though there are constructors,
  1215.      and none accept the initializer, just do a bitwise
  1216.      copy.
  1217.  
  1218.      The above sounds wrong, ``If a class has any copy
  1219.      constructor defined, the default copy constructor will
  1220.      not be generated.'' 12.8 Copying Class Objects  (mrs)
  1221.  
  1222.      @@ This should reject initializer which a constructor
  1223.      @@ rejected on visibility gounds, but there is
  1224.      @@ no way right now to recognize that case with
  1225.      @@ just `error_mark_node'.  */
  1226.       tree itype;
  1227.       init = TREE_VALUE (parms);
  1228.       itype = TREE_TYPE (init);
  1229.       if (TREE_CODE (itype) == REFERENCE_TYPE)
  1230.     {
  1231.       init = convert_from_reference (init);
  1232.       itype = TREE_TYPE (init);
  1233.     }
  1234.       itype = TYPE_MAIN_VARIANT (itype);
  1235.  
  1236.       /* This is currently how the default X(X&) constructor
  1237.      is implemented.  */
  1238.       if (comptypes (TYPE_MAIN_VARIANT (type), itype, 0))
  1239.     {
  1240. #if 0
  1241.       warning ("bitwise copy in initialization of type `%s'",
  1242.            TYPE_NAME_STRING (type));
  1243. #endif
  1244.       rval = build (INIT_EXPR, type, exp, init);
  1245.       expand_expr_stmt (rval);
  1246.     }
  1247.       else
  1248.     {
  1249.       error_with_aggr_type (binfo, "in base initialization for class `%s',");
  1250.       error_with_aggr_type (type, "invalid initializer to constructor for type `%s'");
  1251.       return;
  1252.     }
  1253.     }
  1254.   else
  1255.     {
  1256.       if (init == NULL_TREE)
  1257.     my_friendly_assert (parms == NULL_TREE, 210);
  1258.       if (parms == NULL_TREE && TREE_VIA_VIRTUAL (binfo))
  1259.     error_with_aggr_type (binfo, "virtual baseclass `%s' does not have default initializer");
  1260.       else
  1261.     {
  1262.       error_with_aggr_type (binfo, "in base initialization for class `%s',");
  1263.       /* This will make an error message for us.  */
  1264.       build_method_call (exp, constructor_name (type), parms, binfo,
  1265.                  (TYPE_USES_VIRTUAL_BASECLASSES (type)
  1266.                   ? LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE
  1267.                   : LOOKUP_NORMAL));
  1268.     }
  1269.       return;
  1270.     }
  1271.   /* Constructor has been called, but vtables may be for TYPE
  1272.      rather than for FOR_TYPE.  */
  1273. }
  1274.  
  1275. /* This function is responsible for initializing EXP with INIT
  1276.    (if any).
  1277.  
  1278.    BINFO is the binfo of the type for who we are performing the
  1279.    initialization.  For example, if W is a virtual base class of A and B,
  1280.    and C : A, B.
  1281.    If we are initializing B, then W must contain B's W vtable, whereas
  1282.    were we initializing C, W must contain C's W vtable.
  1283.  
  1284.    TRUE_EXP is nonzero if it is the true expression being initialized.
  1285.    In this case, it may be EXP, or may just contain EXP.  The reason we
  1286.    need this is because if EXP is a base element of TRUE_EXP, we
  1287.    don't necessarily know by looking at EXP where its virtual
  1288.    baseclass fields should really be pointing.  But we do know
  1289.    from TRUE_EXP.  In constructors, we don't know anything about
  1290.    the value being initialized.
  1291.  
  1292.    ALIAS_THIS serves the same purpose it serves for expand_aggr_init.
  1293.  
  1294.    FLAGS is just passes to `build_method_call'.  See that function for
  1295.    its description.  */
  1296.  
  1297. static void
  1298. expand_aggr_init_1 (binfo, true_exp, exp, init, alias_this, flags)
  1299.      tree binfo;
  1300.      tree true_exp, exp;
  1301.      tree init;
  1302.      int alias_this;
  1303.      int flags;
  1304. {
  1305.   tree type = TREE_TYPE (exp);
  1306.   tree init_type = NULL_TREE;
  1307.   tree rval;
  1308.  
  1309.   my_friendly_assert (init != error_mark_node && type != error_mark_node, 211);
  1310.  
  1311.   /* Use a function returning the desired type to initialize EXP for us.
  1312.      If the function is a constructor, and its first argument is
  1313.      NULL_TREE, know that it was meant for us--just slide exp on
  1314.      in and expand the constructor.  Constructors now come
  1315.      as TARGET_EXPRs.  */
  1316.   if (init)
  1317.     {
  1318.       tree init_list = NULL_TREE;
  1319.  
  1320.       if (TREE_CODE (init) == TREE_LIST)
  1321.     {
  1322.       init_list = init;
  1323.       if (TREE_CHAIN (init) == NULL_TREE)
  1324.         init = TREE_VALUE (init);
  1325.     }
  1326.  
  1327.       init_type = TREE_TYPE (init);
  1328.  
  1329.       if (TREE_CODE (init) != TREE_LIST)
  1330.     {
  1331.       if (TREE_CODE (init_type) == ERROR_MARK)
  1332.         return;
  1333.  
  1334. #if 0
  1335.       /* These lines are found troublesome 5/11/89.  */
  1336.       if (TREE_CODE (init_type) == REFERENCE_TYPE)
  1337.         init_type = TREE_TYPE (init_type);
  1338. #endif
  1339.  
  1340.       /* This happens when we use C++'s functional cast notation.
  1341.          If the types match, then just use the TARGET_EXPR
  1342.          directly.  Otherwise, we need to create the initializer
  1343.          separately from the object being initialized.  */
  1344.       if (TREE_CODE (init) == TARGET_EXPR)
  1345.         {
  1346.           if (init_type == type)
  1347.         {
  1348.           if (TREE_CODE (exp) == VAR_DECL
  1349.               || TREE_CODE (exp) == RESULT_DECL)
  1350.             /* Unify the initialization targets.  */
  1351.             DECL_RTL (TREE_OPERAND (init, 0)) = DECL_RTL (exp);
  1352.           else
  1353.             DECL_RTL (TREE_OPERAND (init, 0)) = expand_expr (exp, 0, 0, 0);
  1354.  
  1355.           expand_expr_stmt (init);
  1356.           return;
  1357.         }
  1358.           else
  1359.         {
  1360.           init = TREE_OPERAND (init, 1);
  1361.           init = build (CALL_EXPR, init_type,
  1362.                 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
  1363.           TREE_SIDE_EFFECTS (init) = 1;
  1364. #if 0
  1365.           TREE_RAISES (init) = ??
  1366. #endif
  1367.             if (init_list)
  1368.               TREE_VALUE (init_list) = init;
  1369.         }
  1370.         }
  1371.  
  1372.       if (init_type == type && TREE_CODE (init) == CALL_EXPR
  1373. #if 0
  1374.           /* It is legal to directly initialize from a CALL_EXPR
  1375.          without going through X(X&), apparently.  */
  1376.           && ! TYPE_GETS_INIT_REF (type)
  1377. #endif
  1378.           )
  1379.         {
  1380.           /* A CALL_EXPR is a legitimate form of initialization, so
  1381.          we should not print this warning message.  */
  1382. #if 0
  1383.           /* Should have gone away due to 5/11/89 change.  */
  1384.           if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
  1385.         init = convert_from_reference (init);
  1386. #endif
  1387.           expand_assignment (exp, init, 0, 0);
  1388.           if (exp == DECL_RESULT (current_function_decl))
  1389.         {
  1390.           /* Failing this assertion means that the return value
  1391.              from receives multiple initializations.  */
  1392.           my_friendly_assert (DECL_INITIAL (exp) == NULL_TREE
  1393.                       || DECL_INITIAL (exp) == error_mark_node,
  1394.                       212);
  1395.           DECL_INITIAL (exp) = init;
  1396.         }
  1397.           return;
  1398.         }
  1399.       else if (init_type == type
  1400.            && TREE_CODE (init) == COND_EXPR)
  1401.         {
  1402.           /* Push value to be initialized into the cond, where possible.
  1403.              Avoid spurious warning messages when initializing the
  1404.          result of this function.  */
  1405.           TREE_OPERAND (init, 1)
  1406.         = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 1));
  1407.           if (exp == DECL_RESULT (current_function_decl))
  1408.         DECL_INITIAL (exp) = NULL_TREE;
  1409.           TREE_OPERAND (init, 2)
  1410.         = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 2));
  1411.           if (exp == DECL_RESULT (current_function_decl))
  1412.         DECL_INITIAL (exp) = init;
  1413.           expand_expr (init, const0_rtx, VOIDmode, 0);
  1414.           free_temp_slots ();
  1415.           return;
  1416.         }
  1417.     }
  1418.  
  1419.       /* We did not know what we were initializing before.  Now we do.  */
  1420.       if (TREE_CODE (init) == TARGET_EXPR)
  1421.     {
  1422.       tree tmp = TREE_OPERAND (TREE_OPERAND (init, 1), 1);
  1423.  
  1424.       if (TREE_CODE (TREE_VALUE (tmp)) == NOP_EXPR
  1425.           && TREE_OPERAND (TREE_VALUE (tmp), 0) == integer_zero_node)
  1426.         {
  1427.           /* In order for this to work for RESULT_DECLs, if their
  1428.          type has a constructor, then they must be BLKmode
  1429.          so that they will be meaningfully addressable.  */
  1430.           tree arg = build_unary_op (ADDR_EXPR, exp, 0);
  1431.           init = TREE_OPERAND (init, 1);
  1432.           init = build (CALL_EXPR, build_pointer_type (TREE_TYPE (init)),
  1433.                 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
  1434.           TREE_SIDE_EFFECTS (init) = 1;
  1435. #if 0
  1436.           TREE_RAISES (init) = ??
  1437. #endif
  1438.           TREE_VALUE (TREE_OPERAND (init, 1))
  1439.         = convert_pointer_to (TREE_TYPE (TREE_TYPE (TREE_VALUE (tmp))), arg);
  1440.  
  1441.           if (alias_this)
  1442.         {
  1443.           expand_assignment (current_function_decl, init, 0, 0);
  1444.           return;
  1445.         }
  1446.           if (exp == DECL_RESULT (current_function_decl))
  1447.         {
  1448.           if (DECL_INITIAL (DECL_RESULT (current_function_decl)))
  1449.             fatal ("return value from function receives multiple initializations");
  1450.           DECL_INITIAL (exp) = init;
  1451.         }
  1452.           expand_expr_stmt (init);
  1453.           return;
  1454.         }
  1455.     }
  1456.  
  1457.       /* Handle this case: when calling a constructor: xyzzy foo(bar);
  1458.      which really means:  xyzzy foo = bar; Ugh!
  1459.  
  1460.      We can also be called with an initializer for an object
  1461.      which has virtual functions, but no constructors.  In that
  1462.      case, we perform the assignment first, then initialize
  1463.      the virtual function table pointer fields.  */
  1464.  
  1465.       if (! TYPE_NEEDS_CONSTRUCTING (type))
  1466.     {
  1467.       if (init_list && TREE_CHAIN (init_list))
  1468.         {
  1469.           warning ("initializer list being treated as compound expression");
  1470.           init = convert (TREE_TYPE (exp), build_compound_expr (init_list));
  1471.           if (init == error_mark_node)
  1472.         return;
  1473.         }
  1474.       if (TREE_CODE (exp) == VAR_DECL
  1475.           && TREE_CODE (init) == CONSTRUCTOR
  1476.           && TREE_HAS_CONSTRUCTOR (init)
  1477.           && flag_pic == 0)
  1478.         store_init_value (exp, init);
  1479.       else
  1480.         expand_assignment (exp, init, 0, 0);
  1481.  
  1482.       if (TYPE_VIRTUAL_P (type))
  1483.         expand_recursive_init (binfo, true_exp, exp, init, CLASSTYPE_BASE_INIT_LIST (type), alias_this);
  1484.       return;
  1485.     }
  1486.  
  1487.       /* See whether we can go through a type conversion operator.
  1488.      This wins over going through a non-existent constructor.  If
  1489.      there is a constructor, it is ambiguous.  */
  1490.       if (TREE_CODE (init) != TREE_LIST)
  1491.     {
  1492.       tree ttype = TREE_CODE (init_type) == REFERENCE_TYPE
  1493.         ? TREE_TYPE (init_type) : init_type;
  1494.  
  1495.       if (ttype != type && IS_AGGR_TYPE (ttype))
  1496.         {
  1497.           tree rval = build_type_conversion (CONVERT_EXPR, type, init, 0);
  1498.  
  1499.           if (rval)
  1500.         {
  1501.           /* See if there is a constructor for``type'' that takes a
  1502.              ``ttype''-typed object. */
  1503.           tree parms = build_tree_list (NULL_TREE, init);
  1504.           tree as_cons = NULL_TREE;
  1505.           if (TYPE_HAS_CONSTRUCTOR (type))
  1506.             as_cons = build_method_call (exp, constructor_name (type),
  1507.                          parms, binfo,
  1508.                          LOOKUP_SPECULATIVELY);
  1509.           if (as_cons != NULL_TREE && as_cons != error_mark_node)
  1510.             {
  1511.               tree name = TYPE_NAME (type);
  1512.               if (TREE_CODE (name) == TYPE_DECL)
  1513.             name = DECL_NAME (name);
  1514.               /* ANSI C++ June 5 1992 WP 12.3.2.6.1 */
  1515.               error ("ambiguity between conversion to `%s' and constructor",
  1516.                  IDENTIFIER_POINTER (name));
  1517.             }
  1518.           else
  1519.             expand_assignment (exp, rval, 0, 0);
  1520.           return;
  1521.         }
  1522.         }
  1523.     }
  1524.     }
  1525.  
  1526.   /* Handle default copy constructors here, does not matter if there is
  1527.      a constructor or not.  */
  1528.   if (type == init_type && IS_AGGR_TYPE (type)
  1529.       && init && TREE_CODE (init) != TREE_LIST)
  1530.     expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags);
  1531.   /* Not sure why this is here... */
  1532.   else if (TYPE_HAS_CONSTRUCTOR (type))
  1533.     expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags);
  1534.   else if (TREE_CODE (type) == ARRAY_TYPE)
  1535.     {
  1536.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
  1537.     expand_vec_init (exp, exp, array_type_nelts (type), init, 0);
  1538.       else if (TYPE_VIRTUAL_P (TREE_TYPE (type)))
  1539.     sorry ("arrays of objects with virtual functions but no constructors");
  1540.     }
  1541.   else
  1542.     expand_recursive_init (binfo, true_exp, exp, init,
  1543.                CLASSTYPE_BASE_INIT_LIST (type), alias_this);
  1544. }
  1545.  
  1546. #ifdef MPW
  1547. #pragma segment CPINIT01
  1548. #endif
  1549.  
  1550. /* A pointer which holds the initializer.  First call to
  1551.    expand_aggr_init gets this value pointed to, and sets it to init_null.  */
  1552. static tree *init_ptr, init_null;
  1553.  
  1554. /* Subroutine of expand_recursive_init:
  1555.  
  1556.    ADDR is the address of the expression being initialized.
  1557.    INIT_LIST is the cons-list of initializations to be performed.
  1558.    ALIAS_THIS is its same, lovable self.  */
  1559. static void
  1560. expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this)
  1561.      tree binfo, true_exp, addr;
  1562.      tree init_list;
  1563.      int alias_this;
  1564. {
  1565.   while (init_list)
  1566.     {
  1567.       if (TREE_PURPOSE (init_list))
  1568.     {
  1569.       if (TREE_CODE (TREE_PURPOSE (init_list)) == FIELD_DECL)
  1570.         {
  1571.           tree member = TREE_PURPOSE (init_list);
  1572.           tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), 0);
  1573.           tree member_base = build (COMPONENT_REF, TREE_TYPE (member), subexp, member);
  1574.           if (IS_AGGR_TYPE (TREE_TYPE (member)))
  1575.         expand_aggr_init (member_base, DECL_INITIAL (member), 0);
  1576.           else if (TREE_CODE (TREE_TYPE (member)) == ARRAY_TYPE
  1577.                && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (member)))
  1578.         {
  1579.           member_base = save_expr (default_conversion (member_base));
  1580.           expand_vec_init (member, member_base,
  1581.                    array_type_nelts (TREE_TYPE (member)),
  1582.                    DECL_INITIAL (member), 0);
  1583.         }
  1584.           else expand_expr_stmt (build_modify_expr (member_base, INIT_EXPR, DECL_INITIAL (member)));
  1585.         }
  1586.       else if (TREE_CODE (TREE_PURPOSE (init_list)) == TREE_LIST)
  1587.         {
  1588.           expand_recursive_init_1 (binfo, true_exp, addr, TREE_PURPOSE (init_list), alias_this);
  1589.           expand_recursive_init_1 (binfo, true_exp, addr, TREE_VALUE (init_list), alias_this);
  1590.         }
  1591.       else if (TREE_CODE (TREE_PURPOSE (init_list)) == ERROR_MARK)
  1592.         {
  1593.           /* Only initialize the virtual function tables if we
  1594.          are initializing the ultimate users of those vtables.  */
  1595.           if (TREE_VALUE (init_list))
  1596.         {
  1597.           expand_expr_stmt (build_virtual_init (binfo, TREE_VALUE (init_list), addr));
  1598.           if (TREE_VALUE (init_list) == binfo
  1599.               && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
  1600.             expand_expr_stmt (build_vbase_vtables_init (binfo, binfo, true_exp, addr, 1));
  1601.         }
  1602.         }
  1603.       else my_friendly_abort (49);
  1604.     }
  1605.       else if (TREE_VALUE (init_list)
  1606.            && TREE_CODE (TREE_VALUE (init_list)) == TREE_VEC)
  1607.     {
  1608.       tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), 0);
  1609.       expand_aggr_init_1 (binfo, true_exp, subexp, *init_ptr,
  1610.                   alias_this && BINFO_OFFSET_ZEROP (TREE_VALUE (init_list)),
  1611.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  1612.  
  1613.       /* INIT_PTR is used up.  */
  1614.       init_ptr = &init_null;
  1615.     }
  1616.       else
  1617.     my_friendly_abort (50);
  1618.       init_list = TREE_CHAIN (init_list);
  1619.     }
  1620. }
  1621.  
  1622. /* Initialize EXP with INIT.  Type EXP does not have a constructor,
  1623.    but it has a baseclass with a constructor or a virtual function
  1624.    table which needs initializing.
  1625.  
  1626.    INIT_LIST is a cons-list describing what parts of EXP actually
  1627.    need to be initialized.  INIT is given to the *unique*, first
  1628.    constructor within INIT_LIST.  If there are multiple first
  1629.    constructors, such as with multiple inheritance, INIT must
  1630.    be zero or an ambiguity error is reported.
  1631.  
  1632.    ALIAS_THIS is passed from `expand_aggr_init'.  See comments
  1633.    there.  */
  1634.  
  1635. static void
  1636. expand_recursive_init (binfo, true_exp, exp, init, init_list, alias_this)
  1637.      tree binfo, true_exp, exp, init;
  1638.      tree init_list;
  1639.      int alias_this;
  1640. {
  1641.   tree *old_init_ptr = init_ptr;
  1642.   tree addr = build_unary_op (ADDR_EXPR, exp, 0);
  1643.   init_ptr = &init;
  1644.  
  1645.   if (true_exp == exp && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
  1646.     {
  1647.       expand_aggr_vbase_init (binfo, exp, addr, init_list);
  1648.       expand_expr_stmt (build_vbase_vtables_init (binfo, binfo, true_exp, addr, 1));
  1649.     }
  1650.   expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this);
  1651.  
  1652.   if (*init_ptr)
  1653.     {
  1654.       tree type = TREE_TYPE (exp);
  1655.  
  1656.       if (TREE_CODE (type) == REFERENCE_TYPE)
  1657.     type = TREE_TYPE (type);
  1658.       if (IS_AGGR_TYPE (type))
  1659.     error_with_aggr_type (type, "unexpected argument to constructor `%s'");
  1660.       else
  1661.     error ("unexpected argument to constructor");
  1662.     }
  1663.   init_ptr = old_init_ptr;
  1664. }
  1665.  
  1666. /* Report an error if NAME is not the name of a user-defined,
  1667.    aggregate type.  If OR_ELSE is nonzero, give an error message.  */
  1668. int
  1669. is_aggr_typedef (name, or_else)
  1670.      tree name;
  1671. {
  1672.   tree type;
  1673.  
  1674.   if (name == error_mark_node)
  1675.     return 0;
  1676.  
  1677.   if (! IDENTIFIER_HAS_TYPE_VALUE (name))
  1678.     {
  1679.       if (or_else)
  1680.     error ("`%s' fails to be an aggregate typedef",
  1681.            IDENTIFIER_POINTER (name));
  1682.       return 0;
  1683.     }
  1684.   type = IDENTIFIER_TYPE_VALUE (name);
  1685.   if (! IS_AGGR_TYPE (type))
  1686.     {
  1687.       if (or_else)
  1688.     error ("type `%s' is of non-aggregate type",
  1689.            IDENTIFIER_POINTER (name));
  1690.       return 0;
  1691.     }
  1692.   return 1;
  1693. }
  1694.  
  1695. /* This code could just as well go in `cp-class.c', but is placed here for
  1696.    modularity.  */
  1697.  
  1698. /* For an expression of the form CNAME :: NAME (PARMLIST), build
  1699.    the appropriate function call.  */
  1700. tree
  1701. build_member_call (cname, name, parmlist)
  1702.      tree cname, name, parmlist;
  1703. {
  1704.   tree type, t;
  1705.   tree method_name = name;
  1706.   int dtor = 0;
  1707.   int dont_use_this = 0;
  1708.   tree basetype_path, decl;
  1709.  
  1710.   if (TREE_CODE (method_name) == BIT_NOT_EXPR)
  1711.     {
  1712.       method_name = TREE_OPERAND (method_name, 0);
  1713.       dtor = 1;
  1714.     }
  1715.  
  1716.   if (TREE_CODE (cname) == SCOPE_REF)
  1717.     cname = resolve_scope_to_name (NULL_TREE, cname);
  1718.  
  1719.   if (cname == NULL_TREE || ! is_aggr_typedef (cname, 1))
  1720.     return error_mark_node;
  1721.  
  1722.   /* An operator we did not like.  */
  1723.   if (name == NULL_TREE)
  1724.     return error_mark_node;
  1725.  
  1726.   if (dtor)
  1727.     {
  1728.       if (! TYPE_HAS_DESTRUCTOR (IDENTIFIER_TYPE_VALUE (cname)))
  1729.     error ("type `%s' does not have a destructor",
  1730.            IDENTIFIER_POINTER (cname));
  1731.       else
  1732.     error ("destructor specification error");
  1733.       return error_mark_node;
  1734.     }
  1735.  
  1736.   type = IDENTIFIER_TYPE_VALUE (cname);
  1737.  
  1738.   /* No object?  Then just fake one up, and let build_method_call
  1739.      figure out what to do.  */
  1740.   if (current_class_type == 0
  1741.       || get_base_distance (type, current_class_type, 0, &basetype_path) == -1)
  1742.     dont_use_this = 1;
  1743.  
  1744.   if (dont_use_this)
  1745.     {
  1746.       basetype_path = NULL_TREE;
  1747.       decl = build1 (NOP_EXPR, TYPE_POINTER_TO (type), error_mark_node);
  1748.     }
  1749.   else if (current_class_decl == 0)
  1750.     {
  1751.       dont_use_this = 1;
  1752.       decl = build1 (NOP_EXPR, TYPE_POINTER_TO (type), error_mark_node);
  1753.     }
  1754.   else
  1755.     {
  1756.       decl = current_class_decl;
  1757.       if (TREE_TYPE (decl) != type)
  1758.     decl = convert (TYPE_POINTER_TO (type), decl);
  1759.     }
  1760.  
  1761.   if (t = lookup_fnfields (TYPE_BINFO (type), method_name, 0))
  1762.     return build_method_call (decl, method_name, parmlist, basetype_path,
  1763.                   LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
  1764.   if (TREE_CODE (name) == IDENTIFIER_NODE
  1765.       && (t = lookup_field (TYPE_BINFO (type), name, 1, 0)))
  1766.     {
  1767.       if (t == error_mark_node)
  1768.     return error_mark_node;
  1769.       if (TREE_CODE (t) == FIELD_DECL)
  1770.     {
  1771.       if (dont_use_this)
  1772.         {
  1773.           error ("invalid use of non-static field `%s'",
  1774.              IDENTIFIER_POINTER (name));
  1775.           return error_mark_node;
  1776.         }
  1777.       decl = build (COMPONENT_REF, TREE_TYPE (t), decl, t);
  1778.     }
  1779.       else if (TREE_CODE (t) == VAR_DECL)
  1780.     decl = t;
  1781.       else
  1782.     {
  1783.       error ("invalid use of member `%s::%s'",
  1784.          IDENTIFIER_POINTER (cname), name);
  1785.       return error_mark_node;
  1786.     }
  1787.       if (TYPE_LANG_SPECIFIC (TREE_TYPE (decl))
  1788.       && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (decl)))
  1789.     return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl, parmlist);
  1790.       return build_function_call (decl, parmlist);
  1791.     }
  1792.   else
  1793.     {
  1794.       char *err_name;
  1795.       if (TREE_CODE (name) == IDENTIFIER_NODE)
  1796.     {
  1797.       if (IDENTIFIER_OPNAME_P (name))
  1798.         {
  1799.           char *op_name = operator_name_string (method_name);
  1800.           err_name = (char *)alloca (13 + strlen (op_name));
  1801.           sprintf (err_name, "operator %s", op_name);
  1802.         }
  1803.       else
  1804.         err_name = IDENTIFIER_POINTER (name);
  1805.     }
  1806.       else
  1807.     my_friendly_abort (51);
  1808.  
  1809.       error ("no method `%s::%s'", IDENTIFIER_POINTER (cname), err_name);
  1810.       return error_mark_node;
  1811.     }
  1812. }
  1813.  
  1814. /* Build a reference to a member of an aggregate.  This is not a
  1815.    C++ `&', but really something which can have its address taken,
  1816.    and then act as a pointer to member, for example CNAME :: FIELD
  1817.    can have its address taken by saying & CNAME :: FIELD.
  1818.  
  1819.    @@ Prints out lousy diagnostics for operator <typename>
  1820.    @@ fields.
  1821.  
  1822.    @@ This function should be rewritten and placed in cp-search.c.  */
  1823. tree
  1824. build_offset_ref (cname, name)
  1825.      tree cname, name;
  1826. {
  1827.   tree decl, type, fnfields, fields, t = error_mark_node;
  1828.   tree basetypes = NULL_TREE;
  1829.   int dtor = 0;
  1830.  
  1831.   if (TREE_CODE (cname) == SCOPE_REF)
  1832.     cname = resolve_scope_to_name (NULL_TREE, cname);
  1833.  
  1834.   if (cname == NULL_TREE || ! is_aggr_typedef (cname, 1))
  1835.     return error_mark_node;
  1836.  
  1837.   type = IDENTIFIER_TYPE_VALUE (cname);
  1838.  
  1839.   if (TREE_CODE (name) == BIT_NOT_EXPR)
  1840.     {
  1841.       dtor = 1;
  1842.       name = TREE_OPERAND (name, 0);
  1843.     }
  1844.  
  1845.   if (TYPE_SIZE (type) == 0)
  1846.     {
  1847.       t = IDENTIFIER_CLASS_VALUE (name);
  1848.       if (t == 0)
  1849.     {
  1850.       error_with_aggr_type (type, "incomplete type `%s' does not have member `%s'", IDENTIFIER_POINTER (name));
  1851.       return error_mark_node;
  1852.     }
  1853.       if (TREE_CODE (t) == TYPE_DECL)
  1854.     {
  1855.       error_with_decl (t, "member `%s' is just a type declaration");
  1856.       return error_mark_node;
  1857.     }
  1858.       if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
  1859.     {
  1860.       TREE_USED (t) = 1;
  1861.       return t;
  1862.     }
  1863.       if (TREE_CODE (t) == FIELD_DECL)
  1864.     sorry ("use of member in incomplete aggregate type");
  1865.       else if (TREE_CODE (t) == FUNCTION_DECL)
  1866.     sorry ("use of member function in incomplete aggregate type");
  1867.       else
  1868.     my_friendly_abort (52);
  1869.       return error_mark_node;
  1870.     }
  1871.  
  1872.   if (TREE_CODE (name) == TYPE_EXPR)
  1873.     /* Pass a TYPE_DECL to build_component_type_expr.  */
  1874.     return build_component_type_expr (TYPE_NAME (TREE_TYPE (cname)),
  1875.                       name, NULL_TREE, 1);
  1876.  
  1877.   fnfields = lookup_fnfields (TYPE_BINFO (type), name, 0);
  1878.   fields = lookup_field (type, name, 0, 0);
  1879.  
  1880.   if (fields == error_mark_node)
  1881.     return error_mark_node;
  1882.  
  1883.   if (current_class_type == 0
  1884.       || get_base_distance (type, current_class_type, 0, &basetypes) == -1)
  1885.     {
  1886.       basetypes = TYPE_BINFO (type);
  1887.       decl = build1 (NOP_EXPR,
  1888.              IDENTIFIER_TYPE_VALUE (cname),
  1889.              error_mark_node);
  1890.     }
  1891.   else if (current_class_decl == 0)
  1892.     decl = build1 (NOP_EXPR, IDENTIFIER_TYPE_VALUE (cname),
  1893.            error_mark_node);
  1894.   else decl = C_C_D;
  1895.  
  1896.   if (fnfields)
  1897.     {
  1898.       basetypes = TREE_PURPOSE (fnfields);
  1899.  
  1900.       /* Go from the TREE_BASELINK to the member function info.  */
  1901.       t = TREE_VALUE (fnfields);
  1902.  
  1903.       if (fields)
  1904.     {
  1905.       if (DECL_FIELD_CONTEXT (fields) == DECL_FIELD_CONTEXT (t))
  1906.         {
  1907.           error ("ambiguous member reference: member `%s' defined as both field and function",
  1908.              IDENTIFIER_POINTER (name));
  1909.           return error_mark_node;
  1910.         }
  1911.       if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (fields), DECL_FIELD_CONTEXT (t)))
  1912.         ;
  1913.       else if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (t), DECL_FIELD_CONTEXT (fields)))
  1914.         t = fields;
  1915.       else
  1916.         {
  1917.           error ("ambiguous member reference: member `%s' derives from distinct classes in multiple inheritance lattice");
  1918.           return error_mark_node;
  1919.         }
  1920.     }
  1921.  
  1922.       if (t == TREE_VALUE (fnfields))
  1923.     {
  1924.       extern int flag_save_memoized_contexts;
  1925.  
  1926.       /* This does not handle visibility checking yet.  */
  1927.       if (DECL_CHAIN (t) == NULL_TREE || dtor)
  1928.         {
  1929.           enum visibility_type visibility;
  1930.  
  1931.           /* unique functions are handled easily.  */
  1932.         unique:
  1933.           visibility = compute_visibility (basetypes, t);
  1934.           if (visibility == visibility_protected)
  1935.         {
  1936.           error_with_decl (t, "member function `%s' is protected");
  1937.           error ("in this context");
  1938.           return error_mark_node;
  1939.         }
  1940.           if (visibility == visibility_private)
  1941.         {
  1942.           error_with_decl (t, "member function `%s' is private");
  1943.           error ("in this context");
  1944.           return error_mark_node;
  1945.         }
  1946.           assemble_external (t);
  1947.           return build (OFFSET_REF, TREE_TYPE (t), decl, t);
  1948.         }
  1949.  
  1950.       /* overloaded functions may need more work.  */
  1951.       if (cname == name)
  1952.         {
  1953.           if (TYPE_HAS_DESTRUCTOR (type)
  1954.           && DECL_CHAIN (DECL_CHAIN (t)) == NULL_TREE)
  1955.         {
  1956.           t = DECL_CHAIN (t);
  1957.           goto unique;
  1958.         }
  1959.         }
  1960.       /* FNFIELDS is most likely allocated on the search_obstack,
  1961.          which will go away after this class scope.  If we need
  1962.          to save this value for later (either for memoization
  1963.          or for use as an initializer for a static variable), then
  1964.          do so here.
  1965.  
  1966.          ??? The smart thing to do for the case of saving initializers
  1967.          is to resolve them before we're done with this scope.  */
  1968.       if (!TREE_PERMANENT (fnfields)
  1969.           && ((flag_save_memoized_contexts && global_bindings_p ())
  1970.           || ! allocation_temporary_p ()))
  1971.         fnfields = copy_list (fnfields);
  1972.       t = build_tree_list (error_mark_node, fnfields);
  1973.       TREE_TYPE (t) = build_offset_type (type, unknown_type_node);
  1974.       return t;
  1975.     }
  1976.     }
  1977.  
  1978.   /* Now that we know we are looking for a field, see if we
  1979.      have access to that field.  Lookup_field will give us the
  1980.      error message.  */
  1981.  
  1982.   t = lookup_field (basetypes, name, 1, 0);
  1983.  
  1984.   if (t == error_mark_node)
  1985.     return error_mark_node;
  1986.  
  1987.   if (t == NULL_TREE)
  1988.     {
  1989.       char *print_name;
  1990.  
  1991.       if (name == ansi_opname[(int) TYPE_EXPR])
  1992.     {
  1993.       error ("type conversion operator not a member of type `%s'",
  1994.          IDENTIFIER_POINTER (cname));
  1995.       return error_mark_node;
  1996.     }
  1997.       print_name = operator_name_string (name);
  1998.       /* First character of "<invalid operator>".  */
  1999.       if (print_name[0] == '<')
  2000.     error ("field `%s' is not a member of type `%s'",
  2001.            IDENTIFIER_POINTER (name),
  2002.            IDENTIFIER_POINTER (cname));
  2003.       else
  2004.     error ("operator `%s' is not a member of type `%s'",
  2005.            print_name, IDENTIFIER_POINTER (cname));
  2006.       return error_mark_node;
  2007.     }
  2008.  
  2009.   if (TREE_CODE (t) == TYPE_DECL)
  2010.     {
  2011.       error_with_decl (t, "member `%s' is just a type declaration");
  2012.       return error_mark_node;
  2013.     }
  2014.   /* static class members and class-specific enum
  2015.      values can be returned without further ado.  */
  2016.   if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
  2017.     {
  2018.       assemble_external (t);
  2019.       TREE_USED (t) = 1;
  2020.       return t;
  2021.     }
  2022.  
  2023.   /* static class functions too.  */
  2024.   if (TREE_CODE (t) == FUNCTION_DECL && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
  2025.     my_friendly_abort (53);
  2026.  
  2027.   /* In member functions, the form `cname::name' is no longer
  2028.      equivalent to `this->cname::name'.  */
  2029.   return build (OFFSET_REF, build_offset_type (type, TREE_TYPE (t)), decl, t);
  2030. }
  2031.  
  2032. /* Given an object EXP and a member function reference MEMBER,
  2033.    return the address of the actual member function.  */
  2034. tree
  2035. get_member_function (exp_addr_ptr, exp, member)
  2036.      tree *exp_addr_ptr;
  2037.      tree exp, member;
  2038. {
  2039.   tree ctype = TREE_TYPE (exp);
  2040.   tree function = save_expr (build_unary_op (ADDR_EXPR, member, 0));
  2041.  
  2042.   if (TYPE_VIRTUAL_P (ctype)
  2043.       || (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (ctype)))
  2044.     {
  2045.       tree e0, e1, e3;
  2046.       tree exp_addr;
  2047.  
  2048.       /* Save away the unadulterated `this' pointer.  */
  2049.       exp_addr = save_expr (*exp_addr_ptr);
  2050.  
  2051.       /* Cast function to signed integer.  */
  2052.       e0 = build1 (NOP_EXPR, integer_type_node, function);
  2053.  
  2054. #ifdef VTABLE_USES_MASK
  2055.       /* If we are willing to limit the number of
  2056.      virtual functions a class may have to some
  2057.      *small* number, then if, for a function address,
  2058.      we are passed some small number, we know that
  2059.      it is a virtual function index, and work from there.  */
  2060.       e1 = build (BIT_AND_EXPR, integer_type_node, e0, vtbl_mask);
  2061. #else
  2062.       /* There is a hack here that takes advantage of
  2063.      twos complement arithmetic, and the fact that
  2064.      there are more than one UNITS to the WORD.
  2065.      If the high bit is set for the `function',
  2066.      then we pretend it is a virtual function,
  2067.      and the array indexing will knock this bit
  2068.      out the top, leaving a valid index.  */
  2069.       if (UNITS_PER_WORD <= 1)
  2070.     my_friendly_abort (54);
  2071.  
  2072.       e1 = build (GT_EXPR, integer_type_node, e0, integer_zero_node);
  2073.       e1 = build_compound_expr (tree_cons (NULL_TREE, exp_addr,
  2074.                        build_tree_list (NULL_TREE, e1)));
  2075.       e1 = save_expr (e1);
  2076. #endif
  2077.  
  2078.       if (TREE_SIDE_EFFECTS (*exp_addr_ptr))
  2079.     {
  2080.       exp = build_indirect_ref (exp_addr, 0);
  2081.       *exp_addr_ptr = exp_addr;
  2082.     }
  2083.  
  2084.       /* This is really hairy: if the function pointer is a pointer
  2085.      to a non-virtual member function, then we can't go mucking
  2086.      with the `this' pointer (any more than we already have to
  2087.      this point).  If it is a pointer to a virtual member function,
  2088.      then we have to adjust the `this' pointer according to
  2089.      what the virtual function table tells us.  */
  2090.  
  2091.       e3 = build_vfn_ref (exp_addr_ptr, exp, e0);
  2092.       my_friendly_assert (e3 != error_mark_node, 213);
  2093.  
  2094.       /* Change this pointer type from `void *' to the
  2095.      type it is really supposed to be.  */
  2096.       TREE_TYPE (e3) = TREE_TYPE (function);
  2097.  
  2098.       /* If non-virtual, use what we had originally.  Otherwise,
  2099.      use the value we get from the virtual function table.  */
  2100.       *exp_addr_ptr = build_conditional_expr (e1, exp_addr, *exp_addr_ptr);
  2101.  
  2102.       function = build_conditional_expr (e1, function, e3);
  2103.     }
  2104.   return build_indirect_ref (function, 0);
  2105. }
  2106.  
  2107. /* If a OFFSET_REF made it through to here, then it did
  2108.    not have its address taken.  */
  2109.  
  2110. tree
  2111. resolve_offset_ref (exp)
  2112.      tree exp;
  2113. {
  2114.   tree type = TREE_TYPE (exp);
  2115.   tree base = NULL_TREE;
  2116.   tree member;
  2117.   tree basetype, addr;
  2118.  
  2119.   if (TREE_CODE (exp) == TREE_LIST)
  2120.     return build_unary_op (ADDR_EXPR, exp, 0);
  2121.  
  2122.   if (TREE_CODE (exp) != OFFSET_REF)
  2123.     {
  2124.       my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214);
  2125.       if (TYPE_OFFSET_BASETYPE (type) != current_class_type)
  2126.     {
  2127.       error ("object missing in use of pointer-to-member construct");
  2128.       return error_mark_node;
  2129.     }
  2130.       member = exp;
  2131.       type = TREE_TYPE (type);
  2132.       base = C_C_D;
  2133.     }
  2134.   else
  2135.     {
  2136.       member = TREE_OPERAND (exp, 1);
  2137.       base = TREE_OPERAND (exp, 0);
  2138.     }
  2139.  
  2140.   if (TREE_CODE (member) == VAR_DECL
  2141.       || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE)
  2142.     {
  2143.       /* These were static members.  */
  2144.       if (mark_addressable (member) == 0)
  2145.     return error_mark_node;
  2146.       return member;
  2147.     }
  2148.  
  2149.   /* Syntax error can cause a member which should
  2150.      have been seen as static to be grok'd as non-static.  */
  2151.   if (TREE_CODE (member) == FIELD_DECL && C_C_D == NULL_TREE)
  2152.     {
  2153.       if (TREE_ADDRESSABLE (member) == 0)
  2154.     {
  2155.       error_with_decl (member, "member `%s' is non-static in static member function context");
  2156.       error ("at this point in file");
  2157.       TREE_ADDRESSABLE (member) = 1;
  2158.     }
  2159.       return error_mark_node;
  2160.     }
  2161.  
  2162.   /* The first case is really just a reference to a member of `this'.  */
  2163.   if (TREE_CODE (member) == FIELD_DECL
  2164.       && (base == C_C_D
  2165.       || (TREE_CODE (base) == NOP_EXPR
  2166.           && TREE_OPERAND (base, 0) == error_mark_node)))
  2167.     {
  2168.       tree basetype_path;
  2169.       enum visibility_type visibility;
  2170.  
  2171.       basetype = DECL_CONTEXT (member);
  2172.       if (get_base_distance (basetype, current_class_type, 0, &basetype_path) < 0)
  2173.     {
  2174.       error_not_base_type (basetype, current_class_type);
  2175.       return error_mark_node;
  2176.     }
  2177.       addr = convert_pointer_to (basetype, current_class_decl);
  2178.       visibility = compute_visibility (basetype_path, member);
  2179.       if (visibility == visibility_public)
  2180.     return build (COMPONENT_REF, TREE_TYPE (member),
  2181.               build_indirect_ref (addr, 0), member);
  2182.       if (visibility == visibility_protected)
  2183.     {
  2184.       error_with_decl ("member `%s' is protected");
  2185.       error ("in this context");
  2186.       return error_mark_node;
  2187.     }
  2188.       if (visibility == visibility_private)
  2189.     {
  2190.       error_with_decl ("member `%s' is private");
  2191.       error ("in this context");
  2192.       return error_mark_node;
  2193.     }
  2194.       my_friendly_abort (55);
  2195.     }
  2196.  
  2197.   /* If this is a reference to a member function, then return
  2198.      the address of the member function (which may involve going
  2199.      through the object's vtable), otherwise, return an expression
  2200.      for the dereferenced pointer-to-member construct.  */
  2201.   addr = build_unary_op (ADDR_EXPR, base, 0);
  2202.  
  2203.   if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
  2204.     {
  2205.       basetype = DECL_CLASS_CONTEXT (member);
  2206.       addr = convert_pointer_to (basetype, addr);
  2207.       return build_unary_op (ADDR_EXPR, get_member_function (&addr, build_indirect_ref (addr, 0), member), 0);
  2208.     }
  2209.   else if (TREE_CODE (TREE_TYPE (member)) == OFFSET_TYPE)
  2210.     {
  2211.       basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (member));
  2212.       addr = convert_pointer_to (basetype, addr);
  2213.       member = convert (ptr_type_node, build_unary_op (ADDR_EXPR, member, 0));
  2214.       return build1 (INDIRECT_REF, type,
  2215.              build (PLUS_EXPR, ptr_type_node, addr, member));
  2216.     }
  2217.   my_friendly_abort (56);
  2218.   /* NOTREACHED */
  2219.   return NULL_TREE;
  2220. }
  2221.  
  2222. /* Return either DECL or its known constant value (if it has one).  */
  2223.  
  2224. tree
  2225. decl_constant_value (decl)
  2226.      tree decl;
  2227. {
  2228.   if (! TREE_THIS_VOLATILE (decl)
  2229. #if 0
  2230.       /* These may be necessary for C, but they break C++.  */
  2231.       ! TREE_PUBLIC (decl)
  2232.       /* Don't change a variable array bound or initial value to a constant
  2233.      in a place where a variable is invalid.  */
  2234.       && ! pedantic
  2235. #endif /* 0 */
  2236.       && DECL_INITIAL (decl) != 0
  2237.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  2238.       /* This is invalid if initial value is not constant.
  2239.      If it has either a function call, a memory reference,
  2240.      or a variable, then re-evaluating it could give different results.  */
  2241.       && TREE_CONSTANT (DECL_INITIAL (decl))
  2242.       /* Check for cases where this is sub-optimal, even though valid.  */
  2243.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  2244. #if 0
  2245.       /* We must allow this to work outside of functions so that
  2246.      static constants can be used for array sizes.  */
  2247.       && current_function_decl != 0
  2248.       && DECL_MODE (decl) != BLKmode
  2249. #endif
  2250.       )
  2251.     return DECL_INITIAL (decl);
  2252.   return decl;
  2253. }
  2254.  
  2255. /* Friend handling routines.  */
  2256. /* Friend data structures:
  2257.  
  2258.    Friend lists come from TYPE_DECL nodes.  Since all aggregate
  2259.    types are automatically typedef'd, these node are guaranteed
  2260.    to exist.
  2261.  
  2262.    The TREE_PURPOSE of a friend list is the name of the friend,
  2263.    and its TREE_VALUE is another list.
  2264.  
  2265.    The TREE_PURPOSE of that list is a type, which allows
  2266.    all functions of a given type to be friends.
  2267.    The TREE_VALUE of that list is an individual function
  2268.    which is a friend.
  2269.  
  2270.    Non-member friends will match only by their DECL.  Their
  2271.    member type is NULL_TREE, while the type of the inner
  2272.    list will either be of aggregate type or error_mark_node.  */
  2273.  
  2274. /* Tell if this function specified by DECL
  2275.    can be a friend of type TYPE.
  2276.    Return nonzero if friend, zero otherwise.
  2277.  
  2278.    DECL can be zero if we are calling a constructor or accessing a
  2279.    member in global scope.  */
  2280. int
  2281. is_friend (type, decl)
  2282.      tree type, decl;
  2283. {
  2284.   tree typedecl = TYPE_NAME (type);
  2285.   tree ctype;
  2286.   tree list;
  2287.   tree name;
  2288.  
  2289.   if (decl == NULL_TREE)
  2290.     return 0;
  2291.  
  2292.   ctype = DECL_CLASS_CONTEXT (decl);
  2293.   if (ctype)
  2294.     {
  2295.       list = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (typedecl));
  2296.       while (list)
  2297.     {
  2298.       if (ctype == TREE_VALUE (list))
  2299.         return 1;
  2300.       list = TREE_CHAIN (list);
  2301.     }
  2302.     }
  2303.  
  2304.   list = DECL_FRIENDLIST (typedecl);
  2305.   name = DECL_NAME (decl);
  2306.   while (list)
  2307.     {
  2308.       if (name == TREE_PURPOSE (list))
  2309.     {
  2310.       tree friends = TREE_VALUE (list);
  2311.       name = DECL_ASSEMBLER_NAME (decl);
  2312.       while (friends)
  2313.         {
  2314.           if (ctype == TREE_PURPOSE (friends))
  2315.         return 1;
  2316.           if (name == DECL_ASSEMBLER_NAME (TREE_VALUE (friends)))
  2317.         return 1;
  2318.           friends = TREE_CHAIN (friends);
  2319.         }
  2320.       return 0;
  2321.     }
  2322.       list = TREE_CHAIN (list);
  2323.     }
  2324.   return 0;
  2325. }
  2326.  
  2327. /* Add a new friend to the friends of the aggregate type TYPE.
  2328.    DECL is the FUNCTION_DECL of the friend being added.  */
  2329. static void
  2330. add_friend (type, decl)
  2331.      tree type, decl;
  2332. {
  2333.   tree typedecl = TYPE_NAME (type);
  2334.   tree list = DECL_FRIENDLIST (typedecl);
  2335.   tree name = DECL_NAME (decl);
  2336.   tree ctype = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
  2337.     ? DECL_CLASS_CONTEXT (decl) : error_mark_node;
  2338.  
  2339.   while (list)
  2340.     {
  2341.       if (name == TREE_PURPOSE (list))
  2342.     {
  2343.       tree friends = TREE_VALUE (list);
  2344.       while (friends)
  2345.         {
  2346.           if (decl == TREE_VALUE (friends))
  2347.         {
  2348.           warning_with_decl (decl, "`%s' is already a friend of class `%s'", IDENTIFIER_POINTER (DECL_NAME (typedecl)));
  2349.           return;
  2350.         }
  2351.           friends = TREE_CHAIN (friends);
  2352.         }
  2353.       TREE_VALUE (list) = tree_cons (ctype, decl, TREE_VALUE (list));
  2354.       return;
  2355.     }
  2356.       list = TREE_CHAIN (list);
  2357.     }
  2358.   DECL_FRIENDLIST (typedecl)
  2359.     = tree_cons (DECL_NAME (decl), build_tree_list (error_mark_node, decl),
  2360.          DECL_FRIENDLIST (typedecl));
  2361.   if (DECL_NAME (decl) == ansi_opname[(int) MODIFY_EXPR])
  2362.     {
  2363.       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  2364.       TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2365.       TYPE_GETS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2366.       if (parmtypes && TREE_CHAIN (parmtypes))
  2367.     {
  2368.       tree parmtype = TREE_VALUE (TREE_CHAIN (parmtypes));
  2369.       if (TREE_CODE (parmtype) == REFERENCE_TYPE
  2370.           && TREE_TYPE (parmtypes) == TREE_TYPE (typedecl))
  2371.         {
  2372.           TYPE_HAS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1;
  2373.           TYPE_GETS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1;
  2374.         }
  2375.     }
  2376.     }
  2377. }
  2378.  
  2379. /* Declare that every member function NAME in FRIEND_TYPE
  2380.    (which may be NULL_TREE) is a friend of type TYPE.  */
  2381. static void
  2382. add_friends (type, name, friend_type)
  2383.      tree type, name, friend_type;
  2384. {
  2385.   tree typedecl = TYPE_NAME (type);
  2386.   tree list = DECL_FRIENDLIST (typedecl);
  2387.  
  2388.   while (list)
  2389.     {
  2390.       if (name == TREE_PURPOSE (list))
  2391.     {
  2392.       tree friends = TREE_VALUE (list);
  2393.       while (friends && TREE_PURPOSE (friends) != friend_type)
  2394.         friends = TREE_CHAIN (friends);
  2395.       if (friends)
  2396.         if (friend_type)
  2397.           warning ("method `%s::%s' is already a friend of class",
  2398.                TYPE_NAME_STRING (friend_type),
  2399.                IDENTIFIER_POINTER (name));
  2400.         else
  2401.           warning ("function `%s' is already a friend of class `%s'",
  2402.                IDENTIFIER_POINTER (name),
  2403.                IDENTIFIER_POINTER (DECL_NAME (typedecl)));
  2404.       else
  2405.         TREE_VALUE (list) = tree_cons (friend_type, NULL_TREE,
  2406.                        TREE_VALUE (list));
  2407.       return;
  2408.     }
  2409.       list = TREE_CHAIN (list);
  2410.     }
  2411.   DECL_FRIENDLIST (typedecl) =
  2412.     tree_cons (name,
  2413.            build_tree_list (friend_type, NULL_TREE),
  2414.            DECL_FRIENDLIST (typedecl));
  2415.   if (! strncmp (IDENTIFIER_POINTER (name),
  2416.          IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR]),
  2417.          strlen (IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR]))))
  2418.     {
  2419.       TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2420.       TYPE_GETS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2421.       sorry ("declaring \"friend operator =\" will not find \"operator = (X&)\" if it exists");
  2422.     }
  2423. }
  2424.  
  2425. /* Set up a cross reference so that type TYPE will
  2426.    make member function CTYPE::DECL a friend when CTYPE
  2427.    is finally defined.  */
  2428. void
  2429. xref_friend (type, decl, ctype)
  2430.      tree type, decl, ctype;
  2431. {
  2432.   tree typedecl = TYPE_NAME (type);
  2433.   tree friend_decl = TYPE_NAME (ctype);
  2434.   tree t = tree_cons (NULL_TREE, ctype, DECL_UNDEFINED_FRIENDS (typedecl));
  2435.  
  2436.   DECL_UNDEFINED_FRIENDS (typedecl) = t;
  2437.   SET_DECL_WAITING_FRIENDS (friend_decl, tree_cons (type, t, DECL_WAITING_FRIENDS (friend_decl)));
  2438.   TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = decl;
  2439. }
  2440.  
  2441. #ifdef MPW
  2442. #pragma segment CPINIT02
  2443. #endif
  2444.  
  2445. /* Set up a cross reference so that functions with name NAME and
  2446.    type CTYPE know that they are friends of TYPE.  */
  2447. void
  2448. xref_friends (type, name, ctype)
  2449.      tree type, name, ctype;
  2450. {
  2451.   tree typedecl = TYPE_NAME (type);
  2452.   tree friend_decl = TYPE_NAME (ctype);
  2453.   tree t = tree_cons (NULL_TREE, ctype,
  2454.               DECL_UNDEFINED_FRIENDS (typedecl));
  2455.  
  2456.   DECL_UNDEFINED_FRIENDS (typedecl) = t;
  2457.   SET_DECL_WAITING_FRIENDS (friend_decl, tree_cons (type, t, DECL_WAITING_FRIENDS (friend_decl)));
  2458.   TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = name;
  2459. }
  2460.  
  2461. /* Make FRIEND_TYPE a friend class to TYPE.  If FRIEND_TYPE has already
  2462.    been defined, we make all of its member functions friends of
  2463.    TYPE.  If not, we make it a pending friend, which can later be added
  2464.    when its definition is seen.  If a type is defined, then its TYPE_DECL's
  2465.    DECL_UNDEFINED_FRIENDS contains a (possibly empty) list of friend
  2466.    classes that are not defined.  If a type has not yet been defined,
  2467.    then the DECL_WAITING_FRIENDS contains a list of types
  2468.    waiting to make it their friend.  Note that these two can both
  2469.    be in use at the same time!  */
  2470. void
  2471. make_friend_class (type, friend_type)
  2472.      tree type, friend_type;
  2473. {
  2474.   tree classes;
  2475.  
  2476.   if (type == friend_type)
  2477.     {
  2478.       warning ("class `%s' is implicitly friends with itself",
  2479.            TYPE_NAME_STRING (type));
  2480.       return;
  2481.     }
  2482.  
  2483.   GNU_xref_hier (TYPE_NAME_STRING (type),
  2484.          TYPE_NAME_STRING (friend_type), 0, 0, 1);
  2485.  
  2486.   classes = CLASSTYPE_FRIEND_CLASSES (type);
  2487.   while (classes && TREE_VALUE (classes) != friend_type)
  2488.     classes = TREE_CHAIN (classes);
  2489.   if (classes)
  2490.     warning ("class `%s' is already friends with class `%s'",
  2491.          TYPE_NAME_STRING (TREE_VALUE (classes)), TYPE_NAME_STRING (type));
  2492.   else
  2493.     {
  2494.       CLASSTYPE_FRIEND_CLASSES (type)
  2495.     = tree_cons (NULL_TREE, friend_type, CLASSTYPE_FRIEND_CLASSES (type));
  2496.     }
  2497. }
  2498.  
  2499. /* Main friend processor.  This is large, and for modularity purposes,
  2500.    has been removed from grokdeclarator.  It returns `void_type_node'
  2501.    to indicate that something happened, though a FIELD_DECL is
  2502.    not returned.
  2503.  
  2504.    CTYPE is the class this friend belongs to.
  2505.  
  2506.    DECLARATOR is the name of the friend.
  2507.  
  2508.    DECL is the FUNCTION_DECL that the friend is.
  2509.  
  2510.    In case we are parsing a friend which is part of an inline
  2511.    definition, we will need to store PARM_DECL chain that comes
  2512.    with it into the DECL_ARGUMENTS slot of the FUNCTION_DECL.
  2513.  
  2514.    FLAGS is just used for `grokclassfn'.
  2515.  
  2516.    QUALS say what special qualifies should apply to the object
  2517.    pointed to by `this'.  */
  2518. tree
  2519. do_friend (ctype, declarator, decl, parmdecls, flags, quals)
  2520.      tree ctype, declarator, decl, parmdecls;
  2521.      enum overload_flags flags;
  2522.      tree quals;
  2523. {
  2524.   /* first, lets find out if what we are making a friend needs overloading */
  2525.   tree previous_decl;
  2526.   int was_c_linkage = 0;
  2527.   /* if we find something in scope, let see if it has extern "C" linkage */
  2528.   /* This code is pretty general and should be ripped out and reused
  2529.      as a separate function. */
  2530.   if (DECL_NAME (decl))
  2531.     {
  2532.       previous_decl=lookup_name (DECL_NAME (decl), 0);
  2533.       if (previous_decl && TREE_CODE (previous_decl) == TREE_LIST)
  2534.     {
  2535.       do
  2536.         {
  2537.           if (TREE_TYPE (TREE_VALUE (previous_decl)) == TREE_TYPE (decl))
  2538.         {
  2539.           previous_decl = TREE_VALUE (previous_decl);
  2540.           break;
  2541.         }
  2542.           previous_decl = TREE_CHAIN (previous_decl);
  2543.         }
  2544.       while (previous_decl);
  2545.     }
  2546.       if (previous_decl && TREE_CODE (previous_decl) == FUNCTION_DECL)
  2547.     if (TREE_TYPE (decl) == TREE_TYPE (previous_decl))
  2548.         if (DECL_LANGUAGE (previous_decl) == lang_c)
  2549.         {
  2550.           /* it did, so lets not overload this */
  2551.           was_c_linkage = 1;
  2552.         }
  2553.     }
  2554.       
  2555.   if (ctype)
  2556.     {
  2557.       tree cname = TYPE_NAME (ctype);
  2558.       if (TREE_CODE (cname) == TYPE_DECL)
  2559.     cname = DECL_NAME (cname);
  2560.  
  2561.       /* A method friend.  */
  2562.       if (TREE_CODE (decl) == FUNCTION_DECL)
  2563.     {
  2564.       if (flags == NO_SPECIAL && ctype && declarator == cname)
  2565.         DECL_CONSTRUCTOR_P (decl) = 1;
  2566.  
  2567.       /* This will set up DECL_ARGUMENTS for us.  */
  2568.       grokclassfn (ctype, cname, decl, flags, quals);
  2569.       if (TYPE_SIZE (ctype) != 0)
  2570.         check_classfn (ctype, cname, decl, flags);
  2571.  
  2572.       if (TREE_TYPE (decl) != error_mark_node)
  2573.         {
  2574.           if (TYPE_SIZE (ctype))
  2575.         {
  2576.           /* We don't call pushdecl here yet, or ever on this
  2577.              actual FUNCTION_DECL.  We must preserve its TREE_CHAIN
  2578.              until the end.  */
  2579.           make_decl_rtl (decl, NULL_TREE, 1);
  2580.           add_friend (current_class_type, decl);
  2581.         }
  2582.           else
  2583.         xref_friend (current_class_type, decl, ctype);
  2584.           DECL_FRIEND_P (decl) = 1;
  2585.         }
  2586.     }
  2587.       else
  2588.     {
  2589.       /* Possibly a bunch of method friends.  */
  2590.  
  2591.       /* Get the class they belong to.  */
  2592.       tree ctype = IDENTIFIER_TYPE_VALUE (cname);
  2593.  
  2594.       /* This class is defined, use its methods now.  */
  2595.       if (TYPE_SIZE (ctype))
  2596.         {
  2597.           tree fields = lookup_fnfields (TYPE_BINFO (ctype), declarator, 0);
  2598.           if (fields)
  2599.         add_friends (current_class_type, declarator, ctype);
  2600.           else
  2601.         error ("method `%s' is not a member of class `%s'",
  2602.                IDENTIFIER_POINTER (declarator),
  2603.                IDENTIFIER_POINTER (cname));
  2604.         }
  2605.       else
  2606.         xref_friends (current_class_type, declarator, ctype);
  2607.       decl = void_type_node;
  2608.     }
  2609.     }
  2610.   /* never overload C functions */
  2611.   else if (TREE_CODE (decl) == FUNCTION_DECL
  2612.        && ((IDENTIFIER_LENGTH (declarator) == 4
  2613.         && IDENTIFIER_POINTER (declarator)[0] == 'm'
  2614.         && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  2615.            || (IDENTIFIER_LENGTH (declarator) > 10
  2616.            && IDENTIFIER_POINTER (declarator)[0] == '_'
  2617.            && IDENTIFIER_POINTER (declarator)[1] == '_'
  2618.            && strncmp (IDENTIFIER_POINTER (declarator)+2,
  2619.                    "builtin_", 8) == 0)
  2620.            || was_c_linkage))
  2621.     {
  2622.       /* raw "main", and builtin functions never gets overloaded,
  2623.      but they can become friends.  */
  2624.       TREE_PUBLIC (decl) = 1;
  2625.       add_friend (current_class_type, decl);
  2626.       DECL_FRIEND_P (decl) = 1;
  2627.       if (IDENTIFIER_POINTER (declarator)[0] == '_')
  2628.     {
  2629.       if (! strcmp (IDENTIFIER_POINTER (declarator)+10, "new"))
  2630.         TREE_GETS_NEW (current_class_type) = 0;
  2631.       else if (! strcmp (IDENTIFIER_POINTER (declarator)+10, "delete"))
  2632.         TREE_GETS_DELETE (current_class_type) = 0;
  2633.     }
  2634.       decl = void_type_node;
  2635.     }
  2636.   /* A global friend.
  2637.      @@ or possibly a friend from a base class ?!?  */
  2638.   else if (TREE_CODE (decl) == FUNCTION_DECL)
  2639.     {
  2640.       /* Friends must all go through the overload machinery,
  2641.      even though they may not technically be overloaded.
  2642.  
  2643.      Note that because classes all wind up being top-level
  2644.      in their scope, their friend wind up in top-level scope as well.  */
  2645.       DECL_ASSEMBLER_NAME (decl)
  2646.     = build_decl_overload (declarator, TYPE_ARG_TYPES (TREE_TYPE (decl)),
  2647.                    TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
  2648.       DECL_ARGUMENTS (decl) = parmdecls;
  2649.  
  2650.       /* We can call pushdecl here, because the TREE_CHAIN of this
  2651.      FUNCTION_DECL is not needed for other purposes.  */
  2652.       decl = pushdecl_top_level (decl);
  2653.  
  2654.       make_decl_rtl (decl, NULL_TREE, 1);
  2655.       add_friend (current_class_type, decl);
  2656.  
  2657.       if (! TREE_OVERLOADED (declarator)
  2658.       && IDENTIFIER_GLOBAL_VALUE (declarator)
  2659.       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (declarator)) == FUNCTION_DECL)
  2660.     {
  2661.       error ("friend `%s' implicitly overloaded",
  2662.          IDENTIFIER_POINTER (declarator));
  2663.       error_with_decl (IDENTIFIER_GLOBAL_VALUE (declarator),
  2664.                "after declaration of non-overloaded `%s'");
  2665.     }
  2666.       DECL_FRIEND_P (decl) = 1;
  2667.       DECL_OVERLOADED (decl) = 1;
  2668.       TREE_OVERLOADED (declarator) = 1;
  2669.       decl = push_overloaded_decl (decl, 1);
  2670.     }
  2671.   else
  2672.     {
  2673.       /* @@ Should be able to ingest later definitions of this function
  2674.      before use.  */
  2675.       tree decl = IDENTIFIER_GLOBAL_VALUE (declarator);
  2676.       if (decl == NULL_TREE)
  2677.     {
  2678.       warning ("implicitly declaring `%s' as struct",
  2679.            IDENTIFIER_POINTER (declarator));
  2680.       decl = xref_tag (record_type_node, declarator, NULL_TREE);
  2681.       decl = TYPE_NAME (decl);
  2682.     }
  2683.  
  2684.       /* Allow abbreviated declarations of overloaded functions,
  2685.      but not if those functions are really class names.  */
  2686.       if (TREE_CODE (decl) == TREE_LIST && TREE_TYPE (TREE_PURPOSE (decl)))
  2687.     {
  2688.       warning ("`friend %s' archaic, use `friend class %s' instead",
  2689.            IDENTIFIER_POINTER (declarator),
  2690.            IDENTIFIER_POINTER (declarator));
  2691.       decl = TREE_TYPE (TREE_PURPOSE (decl));
  2692.     }
  2693.  
  2694.       if (TREE_CODE (decl) == TREE_LIST)
  2695.     add_friends (current_class_type, TREE_PURPOSE (decl), NULL_TREE);
  2696.       else
  2697.     make_friend_class (current_class_type, TREE_TYPE (decl));
  2698.       decl = void_type_node;
  2699.     }
  2700.   return decl;
  2701. }
  2702.  
  2703. /* TYPE has now been defined.  It may, however, have a number of things
  2704.    waiting make make it their friend.  We resolve these references
  2705.    here.  */
  2706. void
  2707. embrace_waiting_friends (type)
  2708.      tree type;
  2709. {
  2710.   tree decl = TYPE_NAME (type);
  2711.   tree waiters;
  2712.  
  2713.   if (TREE_CODE (decl) != TYPE_DECL)
  2714.     return;
  2715.  
  2716.   for (waiters = DECL_WAITING_FRIENDS (decl); waiters;
  2717.        waiters = TREE_CHAIN (waiters))
  2718.     {
  2719.       tree waiter = TREE_PURPOSE (waiters);
  2720.       tree waiter_prev = TREE_VALUE (waiters);
  2721.       tree decl = TREE_TYPE (waiters);
  2722.       tree name = decl ? (TREE_CODE (decl) == IDENTIFIER_NODE
  2723.               ? decl : DECL_NAME (decl)) : NULL_TREE;
  2724.       if (name)
  2725.     {
  2726.       /* @@ There may be work to be done since we have not verified
  2727.          @@ consistency between original and friend declarations
  2728.          @@ of the functions waiting to become friends.  */
  2729.       tree field = lookup_fnfields (TYPE_BINFO (type), name, 0);
  2730.       if (field)
  2731.         if (decl == name)
  2732.           add_friends (waiter, name, type);
  2733.         else
  2734.           add_friend (waiter, decl);
  2735.       else
  2736.         error_with_file_and_line (DECL_SOURCE_FILE (TYPE_NAME (waiter)),
  2737.                       DECL_SOURCE_LINE (TYPE_NAME (waiter)),
  2738.                       "no method `%s' defined in class `%s' to be friend",
  2739.                       IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (waiters))),
  2740.                       TYPE_NAME_STRING (type));
  2741.     }
  2742.       else
  2743.     make_friend_class (type, waiter);
  2744.  
  2745.       if (TREE_CHAIN (waiter_prev))
  2746.     TREE_CHAIN (waiter_prev) = TREE_CHAIN (TREE_CHAIN (waiter_prev));
  2747.       else
  2748.     DECL_UNDEFINED_FRIENDS (TYPE_NAME (waiter)) = NULL_TREE;
  2749.     }
  2750. }
  2751.  
  2752. /* Common subroutines of build_new and build_vec_delete.  */
  2753.  
  2754. /* Common interface for calling "builtin" functions that are not
  2755.    really builtin.  */
  2756.  
  2757. tree
  2758. build_builtin_call (type, node, arglist)
  2759.      tree type;
  2760.      tree node;
  2761.      tree arglist;
  2762. {
  2763.   tree rval = build (CALL_EXPR, type, node, arglist, 0);
  2764.   TREE_SIDE_EFFECTS (rval) = 1;
  2765.   assemble_external (TREE_OPERAND (node, 0));
  2766.   TREE_USED (TREE_OPERAND (node, 0)) = 1;
  2767.   return rval;
  2768. }
  2769.  
  2770. /* Generate a C++ "new" expression. DECL is either a TREE_LIST
  2771.    (which needs to go through some sort of groktypename) or it
  2772.    is the name of the class we are newing. INIT is an initialization value.
  2773.    It is either an EXPRLIST, an EXPR_NO_COMMAS, or something in braces.
  2774.    If INIT is void_type_node, it means do *not* call a constructor
  2775.    for this instance.
  2776.  
  2777.    For types with constructors, the data returned is initialized
  2778.    by the appropriate constructor.
  2779.  
  2780.    Whether the type has a constructor or not, if it has a pointer
  2781.    to a virtual function table, then that pointer is set up
  2782.    here.
  2783.  
  2784.    Unless I am mistaken, a call to new () will return initialized
  2785.    data regardless of whether the constructor itself is private or
  2786.    not.
  2787.  
  2788.    Note that build_new does nothing to assure that any special
  2789.    alignment requirements of the type are met.  Rather, it leaves
  2790.    it up to malloc to do the right thing.  Otherwise, folding to
  2791.    the right alignment cal cause problems if the user tries to later
  2792.    free the memory returned by `new'.
  2793.  
  2794.    PLACEMENT is the `placement' list for user-defined operator new ().  */
  2795.  
  2796. tree
  2797. build_new (placement, decl, init, use_global_new)
  2798.      tree placement;
  2799.      tree decl, init;
  2800.      int use_global_new;
  2801. {
  2802.   extern tree require_complete_type ();    /* typecheck.c */
  2803.   tree type, true_type, size, rval;
  2804.   tree init1 = NULL_TREE, nelts;
  2805.   int has_call = 0, has_array = 0;
  2806.  
  2807.   tree pending_sizes = NULL_TREE;
  2808.  
  2809.   if (decl == error_mark_node)
  2810.     return error_mark_node;
  2811.  
  2812.   if (TREE_CODE (decl) == TREE_LIST)
  2813.     {
  2814.       tree absdcl = TREE_VALUE (decl);
  2815.       tree last_absdcl = NULL_TREE;
  2816.       int old_immediate_size_expand;
  2817.  
  2818.       if (current_function_decl
  2819.       && DECL_CONSTRUCTOR_P (current_function_decl))
  2820.     {
  2821.       old_immediate_size_expand = immediate_size_expand;
  2822.       immediate_size_expand = 0;
  2823.     }
  2824.  
  2825.       nelts = integer_one_node;
  2826.  
  2827.       if (absdcl && TREE_CODE (absdcl) == CALL_EXPR)
  2828.     {
  2829.       /* probably meant to be a call */
  2830.       has_call = 1;
  2831.       init1 = TREE_OPERAND (absdcl, 1);
  2832.       absdcl = TREE_OPERAND (absdcl, 0);
  2833.       TREE_VALUE (decl) = absdcl;
  2834.     }
  2835.       while (absdcl && TREE_CODE (absdcl) == INDIRECT_REF)
  2836.     {
  2837.       last_absdcl = absdcl;
  2838.       absdcl = TREE_OPERAND (absdcl, 0);
  2839.     }
  2840.  
  2841.       if (absdcl && TREE_CODE (absdcl) == ARRAY_REF)
  2842.     {
  2843.       /* probably meant to be a vec new */
  2844.       tree this_nelts;
  2845.  
  2846.       has_array = 1;
  2847.       this_nelts = TREE_OPERAND (absdcl, 1);
  2848.       if (this_nelts != error_mark_node)
  2849.         {
  2850.           this_nelts = save_expr (this_nelts);
  2851.           absdcl = TREE_OPERAND (absdcl, 0);
  2852.           if (this_nelts == NULL_TREE)
  2853.         error ("new of array type fails to specify size");
  2854.           else if (this_nelts == integer_zero_node)
  2855.         {
  2856.           warning ("zero size array reserves no space");
  2857.           nelts = integer_zero_node;
  2858.         }
  2859.           else
  2860.         nelts = build_binary_op (MULT_EXPR, nelts, this_nelts);
  2861.         }
  2862.       else
  2863.         nelts = integer_zero_node;
  2864.     }
  2865.  
  2866.       if (last_absdcl)
  2867.     TREE_OPERAND (last_absdcl, 0) = absdcl;
  2868.       else
  2869.     TREE_VALUE (decl) = absdcl;
  2870.  
  2871.       type = true_type = groktypename (decl);
  2872.       if (! type || type == error_mark_node
  2873.       || true_type == error_mark_node)
  2874.     return error_mark_node;
  2875.  
  2876.       /* ``A reference cannot be created by the new operator.  A reference
  2877.      is not an object (8.2.2, 8.4.3), so a pointer to it could not be
  2878.      returned by new.'' ARM 5.3.3 */
  2879.       if (TREE_CODE (type) == REFERENCE_TYPE)
  2880.     error ("new cannot be applied to a reference type");
  2881.  
  2882.       type = TYPE_MAIN_VARIANT (type);
  2883.       if (type == void_type_node)
  2884.     {
  2885.       error ("invalid type: `void []'");
  2886.       return error_mark_node;
  2887.     }
  2888.       if (current_function_decl
  2889.       && DECL_CONSTRUCTOR_P (current_function_decl))
  2890.     {
  2891.       pending_sizes = get_pending_sizes ();
  2892.       immediate_size_expand = old_immediate_size_expand;
  2893.     }
  2894.     }
  2895.   else if (TREE_CODE (decl) == IDENTIFIER_NODE)
  2896.     {
  2897.       if (IDENTIFIER_HAS_TYPE_VALUE (decl))
  2898.     {
  2899.       /* An aggregate type.  */
  2900.       type = IDENTIFIER_TYPE_VALUE (decl);
  2901.       decl = TYPE_NAME (type);
  2902.     }
  2903.       else
  2904.     {
  2905.       /* A builtin type.  */
  2906.       decl = lookup_name (decl, 1);
  2907.       my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 215);
  2908.       type = TREE_TYPE (decl);
  2909.     }
  2910.       true_type = type;
  2911.     }
  2912.   else if (TREE_CODE (decl) == TYPE_DECL)
  2913.     {
  2914.       type = TREE_TYPE (decl);
  2915.       true_type = type;
  2916.     }
  2917.   else
  2918.     {
  2919.       type = decl;
  2920.       true_type = type;
  2921.       decl = TYPE_NAME (type);
  2922.     }
  2923.  
  2924.   if (TYPE_SIZE (type) == 0)
  2925.     {
  2926.       if (type == void_type_node)
  2927.     error ("invalid type for new: `void'");
  2928.       else
  2929.     incomplete_type_error (0, type);
  2930.       return error_mark_node;
  2931.     }
  2932.  
  2933.   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  2934.     {
  2935.       abstract_virtuals_error (NULL_TREE, type);
  2936.       return error_mark_node;
  2937.     }
  2938.  
  2939.   /* If our base type is an array, then make sure we know how many elements
  2940.      it has.  */
  2941.   while (TREE_CODE (type) == ARRAY_TYPE)
  2942.     {
  2943.       tree this_nelts = array_type_nelts_top (type);
  2944.       if (nelts == integer_one_node)
  2945.     {
  2946.       has_array = 1;
  2947.       nelts = this_nelts;
  2948.     }
  2949.       else
  2950.     {
  2951.       my_friendly_assert (has_array != 0, 216);
  2952.       nelts = build_binary_op (MULT_EXPR, nelts, this_nelts);
  2953.     }
  2954.       type = TREE_TYPE (type);
  2955.     }
  2956.   if (has_array)
  2957.     size = fold (build_binary_op (MULT_EXPR, size_in_bytes (type), nelts));
  2958.   else
  2959.     size = size_in_bytes (type);
  2960.  
  2961.   if (has_call)
  2962.     init = init1;
  2963.  
  2964.   /* Get to the target type of TRUE_TYPE, so we can decide whether
  2965.      any constructors need to be called or not.  */
  2966.   type = true_type;
  2967.   while (TREE_CODE (type) == ARRAY_TYPE)
  2968.     type = TREE_TYPE (type);
  2969.  
  2970. #ifdef SOS
  2971.   rval = NULL_TREE;
  2972.   if (placement == void_type_node)
  2973.     {
  2974.       /* Simple "new dynamic" construct.  */
  2975.       if (! IS_AGGR_TYPE (type))
  2976.     {
  2977.       error ("dynamic new can only allocate objects of aggregate type");
  2978.       return error_mark_node;
  2979.     }
  2980.       else if (! is_aggr_typedef (TYPE_IDENTIFIER (type), 1))
  2981.     return error_mark_node;
  2982.       else
  2983.     rval = build_dynamic_new (type, size, NULL_TREE, init);
  2984.     }
  2985.   else if (placement && TREE_CODE (placement) == STRING_CST)
  2986.     {
  2987.       /* A "new dynamic" construct with filename argument.  */
  2988.       if (! IS_AGGR_TYPE (type))
  2989.     {
  2990.       error ("dynamic new can only allocate objects of aggregate type");
  2991.       return error_mark_node;
  2992.     }
  2993.       else if (! is_aggr_typedef (TYPE_IDENTIFIER (type), 1))
  2994.     return error_mark_node;
  2995.       else
  2996.     rval = build_dynamic_new (type, size, placement, init);
  2997.     }
  2998.   if (rval)
  2999.     {
  3000. #if 0
  3001.       /* See comment above as to why this is disabled.  */
  3002.       if (alignment)
  3003.     {
  3004.       rval = build (PLUS_EXPR, TYPE_POINTER_TO (type), rval, alignment);
  3005.       rval = build (BIT_AND_EXPR, TYPE_POINTER_TO (type),
  3006.             rval, build1 (BIT_NOT_EXPR, integer_type_node, alignment));
  3007.     }
  3008. #endif
  3009.       goto done;
  3010.     }
  3011. #endif
  3012.  
  3013.   /* Get a little extra space to store a couple of things before the new'ed
  3014.      array. */
  3015.   if (has_array && TYPE_NEEDS_DESTRUCTOR (true_type))
  3016.     {
  3017.       tree extra = BI_header_size;
  3018.  
  3019.       size = size_binop (PLUS_EXPR, size, extra);
  3020.     }
  3021.  
  3022.   /* Allocate the object. */
  3023.   if (TYPE_LANG_SPECIFIC (true_type)
  3024.       && (TREE_GETS_NEW (true_type) && !use_global_new))
  3025.     rval = build_opfncall (NEW_EXPR, LOOKUP_NORMAL,
  3026.                TYPE_POINTER_TO (true_type), size, placement);
  3027.   else if (placement)
  3028.     {
  3029.       rval = build_opfncall (NEW_EXPR, LOOKUP_GLOBAL|LOOKUP_COMPLAIN,
  3030.                  ptr_type_node, size, placement);
  3031.       rval = convert (TYPE_POINTER_TO (true_type), rval);
  3032.     }
  3033.   else if (flag_this_is_variable > 0
  3034.        && TYPE_HAS_CONSTRUCTOR (true_type) && init != void_type_node)
  3035.     {
  3036.       if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
  3037.     rval = NULL_TREE;
  3038.       else
  3039.     {
  3040.       error ("constructors take parameter lists");
  3041.       return error_mark_node;
  3042.     }
  3043.     }
  3044.   else
  3045.     {
  3046.       rval = build_builtin_call (build_pointer_type (true_type),
  3047.                  BIN, build_tree_list (NULL_TREE, size));
  3048. #if 0
  3049.       /* See comment above as to why this is disabled.  */
  3050.       if (alignment)
  3051.     {
  3052.       rval = build (PLUS_EXPR, TYPE_POINTER_TO (true_type), rval,
  3053.             alignment);
  3054.       rval = build (BIT_AND_EXPR, TYPE_POINTER_TO (true_type),
  3055.             rval, build1 (BIT_NOT_EXPR, integer_type_node,
  3056.                       alignment));
  3057.     }
  3058. #endif
  3059.       TREE_CALLS_NEW (rval) = 1;
  3060.       TREE_SIDE_EFFECTS (rval) = 1;
  3061.     }
  3062.  
  3063.   /* if rval is NULL_TREE I don't have to allocate it, but are we totally
  3064.      sure we have some extra bytes in that case for the BI_header_size
  3065.      cookies? And how does that interact with the code below? (mrs) */
  3066.   /* Finish up some magic for new'ed arrays */
  3067.   if (has_array && TYPE_NEEDS_DESTRUCTOR (true_type) && rval != NULL_TREE)
  3068.     {
  3069.       tree extra = BI_header_size;
  3070.       tree cookie, exp1, exp2;
  3071.       rval = convert (ptr_type_node, rval);    /* convert to void * first */
  3072.       rval = convert (string_type_node, rval); /* lets not add void* and ints */
  3073.       rval = save_expr (build_binary_op (PLUS_EXPR, rval, extra));
  3074.       /* Store header info.  */
  3075.       cookie = build_indirect_ref (build (MINUS_EXPR, TYPE_POINTER_TO (BI_header_type),
  3076.                       rval, extra), 0);
  3077.       exp1 = build (MODIFY_EXPR, void_type_node,
  3078.             build_component_ref (cookie, get_identifier ("nelts"), 0, 0),
  3079.             nelts);
  3080.       TREE_SIDE_EFFECTS (exp1) = 1;
  3081.       exp2 = build (MODIFY_EXPR, void_type_node,
  3082.             build_component_ref (cookie, get_identifier ("ptr_2comp"), 0, 0),
  3083.             build (MINUS_EXPR, ptr_type_node, integer_zero_node, rval));
  3084.       TREE_SIDE_EFFECTS (exp2) = 1;
  3085.       rval = convert (build_pointer_type (true_type), rval);
  3086.       TREE_CALLS_NEW (rval) = 1;
  3087.       TREE_SIDE_EFFECTS (rval) = 1;
  3088.       rval = build_compound_expr (tree_cons (NULL_TREE, exp1,
  3089.                          tree_cons (NULL_TREE, exp2,
  3090.                             build_tree_list (NULL_TREE, rval))));
  3091.     }
  3092.  
  3093.   /* We've figured out where the allocation is to go.
  3094.      If we're not eliding constructors, then if a constructor
  3095.      is defined, we must go through it.  */
  3096.   if (!has_array && (rval == NULL_TREE || !flag_elide_constructors)
  3097.       && TYPE_HAS_CONSTRUCTOR (true_type) && init != void_type_node)
  3098.     {
  3099.       tree newrval;
  3100.       /* Constructors are never virtual.  */
  3101.       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL;
  3102.       /* If a copy constructor might work, set things up so that we can
  3103.      try that after this. */
  3104.       if (rval != NULL_TREE)
  3105.     flags = ~LOOKUP_COMPLAIN & (flags|LOOKUP_SPECULATIVELY);
  3106.       
  3107.       if (rval && TYPE_USES_VIRTUAL_BASECLASSES (true_type))
  3108.     {
  3109.       init = tree_cons (NULL_TREE, integer_one_node, init);
  3110.       flags |= LOOKUP_HAS_IN_CHARGE;
  3111.     }
  3112.       newrval = build_method_call (rval, constructor_name (true_type),
  3113.                 init, NULL_TREE, flags);
  3114.       if (newrval)
  3115.     {
  3116.       rval = newrval;
  3117.       TREE_HAS_CONSTRUCTOR (rval) = 1;
  3118.       goto done;
  3119.     }
  3120.       /* Didn't find the constructor, maybe it is a call to a copy constructor
  3121.      that we should implement. */
  3122.     }
  3123.  
  3124.   if (rval == error_mark_node)
  3125.     return error_mark_node;
  3126.   rval = save_expr (rval);
  3127.   TREE_HAS_CONSTRUCTOR (rval) = 1;
  3128.  
  3129.   /* Don't call any constructors or do any initialization.  */
  3130.   if (init == void_type_node)
  3131.     goto done;
  3132.  
  3133.   if (TYPE_NEEDS_CONSTRUCTING (type)
  3134.       || (has_call || init))
  3135.     {
  3136.       extern tree static_aggregates;
  3137.  
  3138.       if (current_function_decl == NULL_TREE)
  3139.     {
  3140.       /* In case of static initialization, SAVE_EXPR is good enough.  */
  3141.       init = copy_to_permanent (init);
  3142.       rval = copy_to_permanent (rval);
  3143.       static_aggregates = perm_tree_cons (init, rval, static_aggregates);
  3144.     }
  3145.       else
  3146.     {
  3147.       /* Have to wrap this in RTL_EXPR for two cases:
  3148.          in base or member initialization and if we
  3149.          are a branch of a ?: operator.  Since we
  3150.          can't easily know the latter, just do it always.  */
  3151.       tree xval = make_node (RTL_EXPR);
  3152.  
  3153.       TREE_TYPE (xval) = TREE_TYPE (rval);
  3154.       do_pending_stack_adjust ();
  3155.       start_sequence ();
  3156.  
  3157.       /* As a matter of principle, `start_sequence' should do this.  */
  3158.       emit_note (0, -1);
  3159.  
  3160.       if (has_array)
  3161.         rval = expand_vec_init (decl, rval,
  3162.                     build_binary_op (MINUS_EXPR, nelts, integer_one_node),
  3163.                     init, 0);
  3164.       else
  3165.         expand_aggr_init (build_indirect_ref (rval, 0), init, 0);
  3166.  
  3167.       do_pending_stack_adjust ();
  3168.  
  3169.       TREE_SIDE_EFFECTS (xval) = 1;
  3170.       TREE_CALLS_NEW (xval) = 1;
  3171.       RTL_EXPR_SEQUENCE (xval) = get_insns ();
  3172.       end_sequence ();
  3173.  
  3174.       if (TREE_CODE (rval) == SAVE_EXPR)
  3175.         {
  3176.           /* Errors may cause this to not get evaluated.  */
  3177.           if (SAVE_EXPR_RTL (rval) == 0)
  3178.         SAVE_EXPR_RTL (rval) = const0_rtx;
  3179.           RTL_EXPR_RTL (xval) = SAVE_EXPR_RTL (rval);
  3180.         }
  3181.       else
  3182.         {
  3183.           my_friendly_assert (TREE_CODE (rval) == VAR_DECL, 217);
  3184.           RTL_EXPR_RTL (xval) = DECL_RTL (rval);
  3185.         }
  3186.       rval = xval;
  3187.     }
  3188.     }
  3189. #if 0
  3190.   /* It would seem that the above code handles this better than the code
  3191.      below. (mrs) */
  3192.   else if (has_call || init)
  3193.     {
  3194.       if (IS_AGGR_TYPE (type))
  3195.     {
  3196.       /*  default copy constructor may be missing from the below. (mrs) */
  3197.       error_with_aggr_type (type, "no constructor for type `%s'");
  3198.       rval = error_mark_node;
  3199.     }
  3200.       else
  3201.     {
  3202.       /* New 2.0 interpretation: `new int (10)' means
  3203.          allocate an int, and initialize it with 10.  */
  3204.  
  3205.       init = build_c_cast (type, init);
  3206.       rval = build (COMPOUND_EXPR, TREE_TYPE (rval),
  3207.             build_modify_expr (build_indirect_ref (rval, 0),
  3208.                        NOP_EXPR, init),
  3209.             rval);
  3210.       TREE_SIDE_EFFECTS (rval) = 1;
  3211.     }
  3212.     }
  3213. #endif
  3214.  done:
  3215.   if (pending_sizes)
  3216.     rval = build_compound_expr (chainon (pending_sizes,
  3217.                      build_tree_list (NULL_TREE, rval)));
  3218.  
  3219.   if (flag_gc)
  3220.     {
  3221.       extern tree gc_visible;
  3222.       tree objbits;
  3223.       tree update_expr;
  3224.  
  3225.       rval = save_expr (rval);
  3226.       /* We don't need a `headof' operation to do this because
  3227.      we know where the object starts.  */
  3228.       objbits = build1 (INDIRECT_REF, unsigned_type_node,
  3229.             build (MINUS_EXPR, ptr_type_node,
  3230.                    rval, c_sizeof (unsigned_type_node)));
  3231.       update_expr = build_modify_expr (objbits, BIT_IOR_EXPR, gc_visible);
  3232.       rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  3233.                          tree_cons (NULL_TREE, update_expr,
  3234.                             build_tree_list (NULL_TREE, rval))));
  3235.     }
  3236.  
  3237.   return save_expr (rval);
  3238. }
  3239.  
  3240. #ifdef SOS
  3241. /* Build a "new dynamic" call for type TYPE.  The size
  3242.    of the object we are newing is SIZE.  If "new dynamic" was
  3243.    given with an argument, that argument is in NAME.
  3244.    PARMS contains the parameters to the constructor.
  3245.    The first parameter must be an `ImportRequest *'.
  3246.  
  3247.    This is slightly hairy, because we must find the correct
  3248.    constructor by hand.  */
  3249. static tree
  3250. build_dynamic_new (type, size, name, parms)
  3251.      tree type, size;
  3252.      tree name, parms;
  3253. {
  3254.   tree import_parms, inner_parms;
  3255.   tree import_ptr = integer_zero_node;
  3256.   /* This variable is supposed to be the address of a "struct ref"
  3257.      object, but how and where should it be defined?  */
  3258.   tree lookup_tmp = integer_zero_node;
  3259.   tree import_tmp = build_unary_op (ADDR_EXPR, get_temp_name (ptr_type_node, 0), 0);
  3260.  
  3261.   if (name)
  3262.     {
  3263.       inner_parms = tree_cons (NULL_TREE, name,
  3264.                    build_tree_list (NULL_TREE, integer_zero_node));
  3265.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  3266.       inner_parms = build_function_call (__sosLookup, inner_parms);
  3267.     }
  3268.   else
  3269.     inner_parms = integer_zero_node;
  3270.  
  3271.   import_parms = build_tree_list (NULL_TREE, inner_parms);
  3272.  
  3273.   if (CLASSTYPE_DYNAMIC_FILENAME (type))
  3274.     {
  3275.       inner_parms = tree_cons (NULL_TREE, CLASSTYPE_DYNAMIC_FILENAME (type),
  3276.                    build_tree_list (NULL_TREE, integer_zero_node));
  3277.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  3278.       inner_parms = build_function_call (__sosLookup, inner_parms);
  3279.     }
  3280.   else
  3281.     inner_parms = integer_zero_node;
  3282.  
  3283.   import_parms = tree_cons (NULL_TREE, inner_parms, import_parms);
  3284.   import_parms = tree_cons (NULL_TREE, CLASSTYPE_TYPENAME_AS_STRING (type), import_parms);
  3285.   /* This is one parameter which could be (but should not be) evaluated twice.  */
  3286.   TREE_VALUE (parms) = save_expr (TREE_VALUE (parms));
  3287.  
  3288.   import_parms = tree_cons (NULL_TREE, TREE_VALUE (parms), import_parms);
  3289.  
  3290.   /* SOS?? Pass the address of a temporary which can hold the pointer
  3291.      to dynamic class table, but how and where is it defined? */
  3292.   import_parms = tree_cons (NULL_TREE, import_tmp, import_parms);
  3293.  
  3294.   import_ptr = build_function_call (__sosImport, import_parms);
  3295.  
  3296.   /* SOS?? Now, generate call to ctor, but using `import_ptr' as the function
  3297.      table.  Return the result of the call to the ctor.  */
  3298.   import_ptr = build1 (NOP_EXPR, TYPE_POINTER_TO (type), import_ptr);
  3299.   return build_method_call (import_ptr, constructor_name (type),
  3300.                 tree_cons (NULL_TREE, import_tmp, parms),
  3301.                 NULL_TREE, LOOKUP_DYNAMIC);
  3302. }
  3303.  
  3304. /* Return the name of the link table (as an IDENTIFIER_NODE)
  3305.    for the given TYPE.  */
  3306. tree
  3307. get_linktable_name (type)
  3308.      tree type;
  3309. {
  3310.   char *buf = (char *)alloca (4 + TYPE_NAME_LENGTH (type) + 1);
  3311.   tree name;
  3312.  
  3313.   my_friendly_assert (TYPE_DYNAMIC (type), 218);
  3314.   sprintf (buf, "ZN_%s_", TYPE_NAME_STRING (type));
  3315.   return get_identifier (buf);
  3316. }
  3317.  
  3318. /* For a given type TYPE, grovel for a function table which
  3319.    can be used to support dynamic linking.  */
  3320. tree
  3321. get_sos_dtable (type, parms)
  3322.      tree type, parms;
  3323. {
  3324.   tree classname = CLASSTYPE_TYPENAME_AS_STRING (type);
  3325.   tree filename = CLASSTYPE_DYNAMIC_FILENAME (type);
  3326.   tree dyn_vtbl;
  3327.   /* This variable is supposed to be the address of a "struct ref"
  3328.      object, but how and where should it be defined?  */
  3329.   tree lookup_tmp = integer_zero_node;
  3330.  
  3331.   my_friendly_assert (TYPE_DYNAMIC (type), 219);
  3332.  
  3333.   if (filename)
  3334.     {
  3335.       tree inner_parms = tree_cons (NULL_TREE, filename,
  3336.                     build_tree_list (NULL_TREE, integer_zero_node));
  3337.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  3338.       parms = build_tree_list (NULL_TREE, build_function_call (__sosLookup, inner_parms));
  3339.     }
  3340.   else
  3341.     parms = build_tree_list (NULL_TREE, integer_zero_node);
  3342.  
  3343.   parms = tree_cons (NULL_TREE, classname, parms);
  3344.  
  3345.   dyn_vtbl = build_function_call (__sosFindCode, parms);
  3346.   TREE_TYPE (dyn_vtbl) = build_pointer_type (ptr_type_node);
  3347.   return dyn_vtbl;
  3348. }
  3349. #endif
  3350.  
  3351. /* `expand_vec_init' performs initialization of a vector of aggregate
  3352.    types.
  3353.  
  3354.    DECL is passed only for error reporting, and provides line number
  3355.    and source file name information.
  3356.    BASE is the space where the vector will be.
  3357.    MAXINDEX is the maximum index of the array (one less than the
  3358.         number of elements).
  3359.    INIT is the (possibly NULL) initializer.
  3360.  
  3361.    FROM_ARRAY is 0 if we should init everything with INIT
  3362.    (i.e., every element initialized from INIT).
  3363.    FROM_ARRAY is 1 if we should index into INIT in parallel
  3364.    with initialization of DECL.
  3365.    FROM_ARRAY is 2 if we should index into INIT in parallel,
  3366.    but use assignment instead of initialization.  */
  3367.  
  3368. tree
  3369. expand_vec_init (decl, base, maxindex, init, from_array)
  3370.      tree decl, base, maxindex, init;
  3371.      int from_array;
  3372. {
  3373.   tree rval;
  3374.   tree iterator, base2 = NULL_TREE;
  3375.   tree type = TREE_TYPE (TREE_TYPE (base));
  3376.   tree size;
  3377.  
  3378.   maxindex = convert (integer_type_node, maxindex);
  3379.   if (maxindex == error_mark_node)
  3380.     return error_mark_node;
  3381.  
  3382.   if (current_function_decl == NULL_TREE)
  3383.     {
  3384.       rval = make_tree_vec (3);
  3385.       TREE_VEC_ELT (rval, 0) = base;
  3386.       TREE_VEC_ELT (rval, 1) = maxindex;
  3387.       TREE_VEC_ELT (rval, 2) = init;
  3388.       return rval;
  3389.     }
  3390.  
  3391.   size = size_in_bytes (type);
  3392.  
  3393.   /* Set to zero in case size is <= 0.  Optimizer will delete this if
  3394.      it is not needed.  */
  3395.   rval = get_temp_regvar (TYPE_POINTER_TO (type), convert (TYPE_POINTER_TO (type),
  3396.                                null_pointer_node));
  3397.   base = default_conversion (base);
  3398.   base = convert (TYPE_POINTER_TO (type), base);
  3399.   expand_assignment (rval, base, 0, 0);
  3400.   base = get_temp_regvar (TYPE_POINTER_TO (type), base);
  3401.  
  3402.   if (init != NULL_TREE
  3403.       && TREE_CODE (init) == CONSTRUCTOR
  3404.       && TREE_TYPE (init) == TREE_TYPE (decl))
  3405.     {
  3406.       /* Initialization of array from {...}.  */
  3407.       tree elts = CONSTRUCTOR_ELTS (init);
  3408.       tree baseref = build1 (INDIRECT_REF, type, base);
  3409.       tree baseinc = build (PLUS_EXPR, TYPE_POINTER_TO (type), base, size);
  3410.       int host_i = TREE_INT_CST_LOW (maxindex);
  3411.  
  3412.       if (IS_AGGR_TYPE (type))
  3413.     {
  3414.       while (elts)
  3415.         {
  3416.           host_i -= 1;
  3417.           expand_aggr_init (baseref, TREE_VALUE (elts), 0);
  3418.  
  3419.           expand_assignment (base, baseinc, 0, 0);
  3420.           elts = TREE_CHAIN (elts);
  3421.         }
  3422.       /* Initialize any elements by default if possible.  */
  3423.       if (host_i >= 0)
  3424.         {
  3425.           if (TYPE_NEEDS_CONSTRUCTING (type) == 0)
  3426.         {
  3427.           if (obey_regdecls)
  3428.             use_variable (DECL_RTL (base));
  3429.           goto done_init;
  3430.         }
  3431.  
  3432.           iterator = get_temp_regvar (integer_type_node,
  3433.                       build_int_2 (host_i, 0));
  3434.           init = NULL_TREE;
  3435.           goto init_by_default;
  3436.         }
  3437.     }
  3438.       else
  3439.     while (elts)
  3440.       {
  3441.         expand_assignment (baseref, TREE_VALUE (elts), 0, 0);
  3442.  
  3443.         expand_assignment (base, baseinc, 0, 0);
  3444.         elts = TREE_CHAIN (elts);
  3445.       }
  3446.  
  3447.       if (obey_regdecls)
  3448.     use_variable (DECL_RTL (base));
  3449.     }
  3450.   else
  3451.     {
  3452.       iterator = get_temp_regvar (integer_type_node, maxindex);
  3453.  
  3454.     init_by_default:
  3455.  
  3456.       /* If initializing one array from another,
  3457.      initialize element by element.  */
  3458.       if (from_array)
  3459.     {
  3460.       if (decl == NULL_TREE
  3461.           || (init && !comptypes (TREE_TYPE (init), TREE_TYPE (decl), 1)))
  3462.         {
  3463.           sorry ("initialization of array from dissimilar array type");
  3464.           return error_mark_node;
  3465.         }
  3466.       if (init)
  3467.         {
  3468.           base2 = default_conversion (init);
  3469.           base2 = get_temp_regvar (TYPE_POINTER_TO (type), base2);
  3470.         }
  3471.       else if (TYPE_LANG_SPECIFIC (type)
  3472.            && TYPE_NEEDS_CONSTRUCTING (type)
  3473.            && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
  3474.         {
  3475.           error ("initializer ends prematurely");
  3476.           return error_mark_node;
  3477.         }
  3478.     }
  3479.  
  3480.       expand_start_cond (build (GE_EXPR, integer_type_node,
  3481.                 iterator, integer_zero_node), 0);
  3482.       expand_start_loop_continue_elsewhere (1);
  3483.  
  3484.       if (from_array)
  3485.     {
  3486.       tree to = build1 (INDIRECT_REF, type, base);
  3487.       tree from;
  3488.  
  3489.       if (base2)
  3490.         from = build1 (INDIRECT_REF, type, base2);
  3491.       else
  3492.         from = NULL_TREE;
  3493.  
  3494.       if (from_array == 2)
  3495.         expand_expr_stmt (build_modify_expr (to, NOP_EXPR, from));
  3496.       else if (TYPE_NEEDS_CONSTRUCTING (type))
  3497.         expand_aggr_init (to, from, 0);
  3498.       else if (from)
  3499.         expand_assignment (to, from, 0, 0);
  3500.       else my_friendly_abort (57);
  3501.     }
  3502.       else if (TREE_CODE (type) == ARRAY_TYPE)
  3503.     {
  3504.       if (init != 0)
  3505.         sorry ("cannot initialize multi-dimensional array with initializer");
  3506.       expand_vec_init (decl, build1 (NOP_EXPR, TYPE_POINTER_TO (TREE_TYPE (type)), base),
  3507.                array_type_nelts (type), 0, 0);
  3508.     }
  3509.       else
  3510.     expand_aggr_init (build1 (INDIRECT_REF, type, base), init, 0);
  3511.  
  3512.       expand_assignment (base,
  3513.              build (PLUS_EXPR, TYPE_POINTER_TO (type), base, size),
  3514.              0, 0);
  3515.       if (base2)
  3516.     expand_assignment (base2,
  3517.                build (PLUS_EXPR, TYPE_POINTER_TO (type), base2, size), 0, 0);
  3518.       expand_loop_continue_here ();
  3519.       expand_exit_loop_if_false (0, build (NE_EXPR, integer_type_node,
  3520.                        build (PREDECREMENT_EXPR, integer_type_node, iterator, integer_one_node), minus_one));
  3521.  
  3522.       if (obey_regdecls)
  3523.     {
  3524.       use_variable (DECL_RTL (base));
  3525.       if (base2)
  3526.         use_variable (DECL_RTL (base2));
  3527.     }
  3528.       expand_end_loop ();
  3529.       expand_end_cond ();
  3530.       if (obey_regdecls)
  3531.     use_variable (DECL_RTL (iterator));
  3532.     }
  3533.  done_init:
  3534.  
  3535.   if (obey_regdecls)
  3536.     use_variable (DECL_RTL (rval));
  3537.   return rval;
  3538. }
  3539.  
  3540. #ifdef MPW
  3541. #pragma segment CPINIT03
  3542. #endif
  3543.  
  3544. /* Free up storage of type TYPE, at address ADDR.
  3545.  
  3546.    TYPE is a POINTER_TYPE and can be ptr_type_node for no special type
  3547.    of pointer.
  3548.  
  3549.    VIRTUAL_SIZE is the ammount of storage that was allocated, and is
  3550.    used as the second argument to operator delete.  It can include
  3551.    things like padding and magic size cookies.  It has virtual in it,
  3552.    because if you have a base pointer and you delete through a virtual
  3553.    destructor, it should be the size of the dynamic object, not the
  3554.    static object, see Free Store 12.5 ANSI C++ WP.
  3555.  
  3556.    This does not call any destructors.  */
  3557. tree
  3558. build_x_delete (type, addr, use_global_delete, virtual_size)
  3559.      tree type, addr, virtual_size;
  3560.      int use_global_delete;
  3561. {
  3562.   tree rval;
  3563.  
  3564.   if (!use_global_delete
  3565.       && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  3566.       && TREE_GETS_DELETE (TREE_TYPE (type)))
  3567.     rval = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr, virtual_size);
  3568.   else
  3569.     rval = build_builtin_call (void_type_node, BID,
  3570.                    tree_cons (NULL_TREE, addr,
  3571.                       build_tree_list (NULL_TREE,
  3572.                                virtual_size)));
  3573.   return rval;
  3574. }
  3575.  
  3576. /* Objects returned by `build_new' may point to just what the user
  3577.    requested (in the case of `new X'), or they may have a cookie
  3578.    consisting of a special value (the two's complement of the pointer
  3579.    address) and the number of elements allocated (in the case of
  3580.    `new X[N]'.  In the latter case, we need to adjust the pointer
  3581.    that's passed back to the storage allocator.  */
  3582.  
  3583. static tree
  3584. maybe_adjust_addr_for_delete (addr)
  3585.      tree addr;
  3586. {
  3587.   tree cookie_addr;
  3588.   tree cookie;
  3589.   tree adjusted_addr, ptr_2comp;
  3590.  
  3591.   if (TREE_SIDE_EFFECTS (addr))
  3592.     addr = save_expr (addr);
  3593.  
  3594.   cookie_addr = build (MINUS_EXPR, TYPE_POINTER_TO (BI_header_type),
  3595.                addr, BI_header_size);
  3596.   cookie = build_indirect_ref (cookie_addr, 0);
  3597.  
  3598.   ptr_2comp = build_component_ref (cookie, get_identifier ("ptr_2comp"), 0, 0);
  3599.   adjusted_addr = save_expr (build (MINUS_EXPR, TREE_TYPE (addr), addr, BI_header_size));
  3600.  
  3601.   /* We must zero out the storage here because if the memory is freed,
  3602.      then later reallocated, we might get a false positive when the
  3603.      address is reused.  */
  3604.   adjusted_addr = build_compound_expr (tree_cons (NULL_TREE,
  3605.                           build_modify_expr (ptr_2comp, NOP_EXPR, null_pointer_node),
  3606.                           build_tree_list (NULL_TREE, adjusted_addr)));
  3607.  
  3608.   addr = build (COND_EXPR, TREE_TYPE (addr),
  3609.         build (TRUTH_ORIF_EXPR, integer_type_node,
  3610.                build (EQ_EXPR, integer_type_node,
  3611.                   addr, integer_zero_node),
  3612.                build (PLUS_EXPR, integer_type_node,
  3613.                   convert (ptr_type_node, addr), ptr_2comp)),
  3614.         addr,
  3615.         adjusted_addr);
  3616.   return addr;
  3617. }
  3618.  
  3619. /* Generate a call to a destructor. TYPE is the type to cast ADDR to.
  3620.    ADDR is an expression which yields the store to be destroyed.
  3621.    AUTO_DELETE is nonzero if a call to DELETE should be made or not.
  3622.    If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the
  3623.    virtual baseclasses.
  3624.    If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate.
  3625.  
  3626.    FLAGS is the logical disjunction of zero or more LOOKUP_
  3627.    flags.  See cp-tree.h for more info.
  3628.  
  3629.    MAYBE_ADJUST is nonzero iff we may need to adjust the address
  3630.    of the object being deleted before calling `operator delete'.
  3631.    This can happen when a user allocates an array with `operator new'
  3632.    and simply calls delete.  Ideally this is unnecessary, but there
  3633.    is much code that does `p = new char[n]; ... delete p;' and this code
  3634.    would crash otherwise.
  3635.  
  3636.    This function does not delete an object's virtual base classes.  */
  3637. tree
  3638. build_delete (type, addr, auto_delete, flags, use_global_delete, maybe_adjust)
  3639.      tree type, addr;
  3640.      tree auto_delete;
  3641.      int flags;
  3642.      int use_global_delete;
  3643.      int maybe_adjust;
  3644. {
  3645.   tree function, parms;
  3646.   tree member;
  3647.   tree expr;
  3648.   tree ref;
  3649.   int ptr;
  3650.  
  3651.   if (addr == error_mark_node)
  3652.     return error_mark_node;
  3653.  
  3654.   /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
  3655.      set to `error_mark_node' before it gets properly cleaned up.  */
  3656.   if (type == error_mark_node)
  3657.     return error_mark_node;
  3658.  
  3659.   type = TYPE_MAIN_VARIANT (type);
  3660.  
  3661.   if (TREE_CODE (type) == POINTER_TYPE)
  3662.     {
  3663.       type = TREE_TYPE (type);
  3664.       if (TYPE_SIZE (type) == 0)
  3665.     {
  3666.       incomplete_type_error (0, type);
  3667.       return error_mark_node;
  3668.     }
  3669.       if (TREE_CODE (type) == ARRAY_TYPE)
  3670.     goto handle_array;
  3671.       if (! IS_AGGR_TYPE (type))
  3672.     {
  3673.       tree virtual_size;
  3674.  
  3675.       /* This is probably wrong. It should be the size of the virtual
  3676.          object being deleted.  */
  3677.       virtual_size = c_sizeof (type);
  3678.  
  3679.       if (maybe_adjust)
  3680.         addr = maybe_adjust_addr_for_delete (addr);
  3681.       return build_builtin_call (void_type_node, BID,
  3682.                      tree_cons (NULL_TREE, addr,
  3683.                         build_tree_list (NULL_TREE, virtual_size)));
  3684.     }
  3685.       if (TREE_SIDE_EFFECTS (addr))
  3686.     addr = save_expr (addr);
  3687.       ref = build_indirect_ref (addr, 0);
  3688.       ptr = 1;
  3689.     }
  3690.   else if (TREE_CODE (type) == ARRAY_TYPE)
  3691.     {
  3692.     handle_array:
  3693.       if (TREE_SIDE_EFFECTS (addr))
  3694.     addr = save_expr (addr);
  3695.       return build_vec_delete (addr, array_type_nelts (type), c_sizeof (TREE_TYPE (type)),
  3696.                    NULL_TREE, auto_delete, integer_two_node);
  3697.     }
  3698.   else
  3699.     {
  3700.       /* Don't check PROTECT here; leave that decision to the
  3701.      destructor.  If the destructor is visible, call it,
  3702.      else report error.  */
  3703.       addr = build_unary_op (ADDR_EXPR, addr, 0);
  3704.       if (TREE_SIDE_EFFECTS (addr))
  3705.     addr = save_expr (addr);
  3706.  
  3707.       if (TREE_CONSTANT (addr))
  3708.     addr = convert_pointer_to (type, addr);
  3709.       else
  3710.     addr = convert_force (build_pointer_type (type), addr);
  3711.  
  3712.       if (TREE_CODE (addr) == NOP_EXPR
  3713.       && TREE_OPERAND (addr, 0) == current_class_decl)
  3714.     ref = C_C_D;
  3715.       else
  3716.     ref = build_indirect_ref (addr, 0);
  3717.       ptr = 0;
  3718.     }
  3719.  
  3720.   my_friendly_assert (IS_AGGR_TYPE (type), 220);
  3721.  
  3722.   if (! TYPE_NEEDS_DESTRUCTOR (type))
  3723.     {
  3724.       tree virtual_size;
  3725.  
  3726.       /* This is probably wrong. It should be the size of the virtual object
  3727.      being deleted.  */
  3728.       virtual_size = c_sizeof (type);
  3729.  
  3730.       if (auto_delete == integer_zero_node)
  3731.     return void_zero_node;
  3732.       if (maybe_adjust && addr != current_class_decl)
  3733.     addr = maybe_adjust_addr_for_delete (addr);
  3734.       if (TREE_GETS_DELETE (type) && !use_global_delete)
  3735.     return build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr, virtual_size);
  3736.       return build_builtin_call (void_type_node, BID,
  3737.                  tree_cons (NULL_TREE, addr,
  3738.                         build_tree_list (NULL_TREE, virtual_size)));
  3739.     }
  3740.   parms = build_tree_list (NULL_TREE, addr);
  3741.  
  3742.   /* Below, we will reverse the order in which these calls are made.
  3743.      If we have a destructor, then that destructor will take care
  3744.      of the base classes; otherwise, we must do that here.  */
  3745.   if (TYPE_HAS_DESTRUCTOR (type))
  3746.     {
  3747.       tree dtor = DECL_MAIN_VARIANT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0));
  3748.       tree basetypes = TYPE_BINFO (type);
  3749.  
  3750.       if (flags & LOOKUP_PROTECT)
  3751.     {
  3752.       enum visibility_type visibility = compute_visibility (basetypes, dtor);
  3753.  
  3754.       if (visibility == visibility_private)
  3755.         {
  3756.           if (flags & LOOKUP_COMPLAIN)
  3757.         error_with_aggr_type (type, "destructor for type `%s' is private in this scope");
  3758.           return error_mark_node;
  3759.         }
  3760.       else if (visibility == visibility_protected
  3761.            && (flags & LOOKUP_PROTECTED_OK) == 0)
  3762.         {
  3763.           if (flags & LOOKUP_COMPLAIN)
  3764.         error_with_aggr_type (type, "destructor for type `%s' is protected in this scope");
  3765.           return error_mark_node;
  3766.         }
  3767.     }
  3768.  
  3769.       /* Once we are in a destructor, try not going through
  3770.      the virtual function table to find the next destructor.  */
  3771.       if (DECL_VINDEX (dtor)
  3772.       && ! (flags & LOOKUP_NONVIRTUAL)
  3773.       && TREE_CODE (auto_delete) != PARM_DECL
  3774.       && (ptr == 1 || ! resolves_to_fixed_type_p (ref, 0)))
  3775.     {
  3776.       /* This destructor must be called via virtual function table.  */
  3777.       dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (DECL_CONTEXT (dtor)), 0);
  3778.       expr = convert_pointer_to (DECL_CLASS_CONTEXT (dtor), TREE_VALUE (parms));
  3779.       if (expr != TREE_VALUE (parms))
  3780.         {
  3781.           expr = fold (expr);
  3782.           ref = build_indirect_ref (expr, 0);
  3783.           TREE_VALUE (parms) = expr;
  3784.         }
  3785.       function = build_vfn_ref (&TREE_VALUE (parms), ref, DECL_VINDEX (dtor));
  3786.       if (function == error_mark_node)
  3787.         return error_mark_node;
  3788.       TREE_TYPE (function) = build_pointer_type (TREE_TYPE (dtor));
  3789.       TREE_CHAIN (parms) = build_tree_list (NULL_TREE, auto_delete);
  3790.       expr = build_function_call (function, parms);
  3791.       if (ptr && (flags & LOOKUP_DESTRUCTOR) == 0)
  3792.         {
  3793.           /* Handle the case where a virtual destructor is
  3794.          being called on an item that is 0.
  3795.  
  3796.          @@ Does this really need to be done?  */
  3797.           tree ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node);
  3798. #if 0
  3799.           if (TREE_CODE (ref) == VAR_DECL
  3800.           || TREE_CODE (ref) == COMPONENT_REF)
  3801.         warning ("losing in build_delete");
  3802. #endif
  3803.           expr = build (COND_EXPR, void_type_node,
  3804.                 ifexp, expr, void_zero_node);
  3805.         }
  3806.     }
  3807.       else
  3808.     {
  3809.       tree ifexp;
  3810.  
  3811.       if ((flags & LOOKUP_DESTRUCTOR)
  3812.           || TREE_CODE (ref) == VAR_DECL
  3813.           || TREE_CODE (ref) == PARM_DECL
  3814.           || TREE_CODE (ref) == COMPONENT_REF
  3815.           || TREE_CODE (ref) == ARRAY_REF)
  3816.         /* These can't be 0.  */
  3817.         ifexp = integer_one_node;
  3818.       else
  3819.         /* Handle the case where a non-virtual destructor is
  3820.            being called on an item that is 0.  */
  3821.         ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node);
  3822.  
  3823.       /* Used to mean that this destructor was known to be empty,
  3824.          but that's now obsolete.  */
  3825.       my_friendly_assert (DECL_INITIAL (dtor) != void_type_node, 221);
  3826.  
  3827.       TREE_CHAIN (parms) = build_tree_list (NULL_TREE, auto_delete);
  3828.       expr = build_function_call (dtor, parms);
  3829.  
  3830.       if (ifexp != integer_one_node)
  3831.         expr = build (COND_EXPR, void_type_node,
  3832.               ifexp, expr, void_zero_node);
  3833.     }
  3834.       return expr;
  3835.     }
  3836.   else
  3837.     {
  3838.       /* This can get visibilities wrong.  */
  3839.       tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
  3840.       int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  3841.       tree base_binfo = n_baseclasses > 0 ? TREE_VEC_ELT (binfos, 0) : NULL_TREE;
  3842.       tree exprstmt = NULL_TREE;
  3843.       tree parent_auto_delete = auto_delete;
  3844.       tree cond;
  3845.  
  3846.       /* If this type does not have a destructor, but does have
  3847.      operator delete, call the parent parent destructor (if any),
  3848.      but let this node do the deleting.  Otherwise, it is ok
  3849.      to let the parent destructor do the deleting.  */
  3850.       if (TREE_GETS_DELETE (type) && !use_global_delete)
  3851.     {
  3852.       parent_auto_delete = integer_zero_node;
  3853.       if (auto_delete == integer_zero_node)
  3854.         cond = NULL_TREE;
  3855.       else
  3856.         {
  3857.           tree virtual_size;
  3858.  
  3859.             /* This is probably wrong. It should be the size of the
  3860.            virtual object being deleted.  */
  3861.           virtual_size = c_sizeof (type);
  3862.  
  3863.           expr = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr,
  3864.                      virtual_size);
  3865.           if (expr == error_mark_node)
  3866.         return error_mark_node;
  3867.           if (auto_delete != integer_one_node)
  3868.         cond = build (COND_EXPR, void_type_node,
  3869.                   build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
  3870.                   expr, void_zero_node);
  3871.           else cond = expr;
  3872.         }
  3873.     }
  3874.       else if (base_binfo == NULL_TREE
  3875.            || (TREE_VIA_VIRTUAL (base_binfo) == 0
  3876.            && ! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))))
  3877.     {
  3878.       tree virtual_size;
  3879.  
  3880.       /* This is probably wrong. It should be the size of the virtual
  3881.          object being deleted.  */
  3882.       virtual_size = c_sizeof (type);
  3883.  
  3884.       cond = build (COND_EXPR, void_type_node,
  3885.             build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
  3886.             build_builtin_call (void_type_node, BID,
  3887.                         tree_cons (NULL_TREE, addr,
  3888.                                build_tree_list (NULL_TREE, virtual_size))),
  3889.             void_zero_node);
  3890.     }
  3891.       else cond = NULL_TREE;
  3892.  
  3893.       if (cond)
  3894.     exprstmt = build_tree_list (NULL_TREE, cond);
  3895.  
  3896.       if (base_binfo
  3897.       && ! TREE_VIA_VIRTUAL (base_binfo)
  3898.       && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))
  3899.     {
  3900.       tree this_auto_delete;
  3901.  
  3902.       if (BINFO_OFFSET_ZEROP (base_binfo))
  3903.         this_auto_delete = parent_auto_delete;
  3904.       else
  3905.         this_auto_delete = integer_zero_node;
  3906.  
  3907.       expr = build_delete (TYPE_POINTER_TO (BINFO_TYPE (base_binfo)), addr,
  3908.                    this_auto_delete, flags|LOOKUP_PROTECTED_OK, 0, 0);
  3909.       exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3910.     }
  3911.  
  3912.       /* Take care of the remaining baseclasses.  */
  3913.       for (i = 1; i < n_baseclasses; i++)
  3914.     {
  3915.       base_binfo = TREE_VEC_ELT (binfos, i);
  3916.       if (! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))
  3917.           || TREE_VIA_VIRTUAL (base_binfo))
  3918.         continue;
  3919.  
  3920.       /* May be zero offset if other baseclasses are virtual.  */
  3921.       expr = fold (build (PLUS_EXPR, TYPE_POINTER_TO (BINFO_TYPE (base_binfo)),
  3922.                   addr, BINFO_OFFSET (base_binfo)));
  3923.  
  3924.       expr = build_delete (TYPE_POINTER_TO (BINFO_TYPE (base_binfo)), expr,
  3925.                    integer_zero_node,
  3926.                    flags|LOOKUP_PROTECTED_OK, 0, 0);
  3927.  
  3928.       exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3929.     }
  3930.  
  3931.       for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
  3932.     {
  3933.       if (TREE_CODE (member) != FIELD_DECL)
  3934.         continue;
  3935.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (member)))
  3936.         {
  3937.           tree this_member = build_component_ref (ref, DECL_NAME (member), 0, 0);
  3938.           tree this_type = TREE_TYPE (member);
  3939.           expr = build_delete (this_type, this_member, integer_two_node, flags, 0, 0);
  3940.           exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3941.         }
  3942.     }
  3943.  
  3944.       if (exprstmt)
  3945.     return build_compound_expr (exprstmt);
  3946.       /* Virtual base classes make this function do nothing.  */
  3947.       return void_zero_node;
  3948.     }
  3949. }
  3950.  
  3951. /* For type TYPE, delete the virtual baseclass objects of DECL.  */
  3952.  
  3953. tree
  3954. build_vbase_delete (type, decl)
  3955.      tree type, decl;
  3956. {
  3957.   tree vbases = CLASSTYPE_VBASECLASSES (type);
  3958.   tree result = NULL_TREE;
  3959.   tree addr = build_unary_op (ADDR_EXPR, decl, 0);
  3960.   my_friendly_assert (addr != error_mark_node, 222);
  3961.   while (vbases)
  3962.     {
  3963.       tree this_addr = convert_force (TYPE_POINTER_TO (BINFO_TYPE (vbases)), addr);
  3964.       result = tree_cons (NULL_TREE,
  3965.               build_delete (TREE_TYPE (this_addr), this_addr,
  3966.                     integer_zero_node,
  3967.                     LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0),
  3968.               result);
  3969.       vbases = TREE_CHAIN (vbases);
  3970.     }
  3971.   return build_compound_expr (nreverse (result));
  3972. }
  3973.  
  3974. /* Build a C++ vector delete expression.
  3975.    MAXINDEX is the number of elements to be deleted.
  3976.    ELT_SIZE is the nominal size of each element in the vector.
  3977.    BASE is the expression that should yield the store to be deleted.
  3978.    DTOR_DUMMY is a placeholder for a destructor.  The library function
  3979.    __builtin_vec_delete has a pointer to function in this position.
  3980.    This function expands (or synthesizes) these calls itself.
  3981.    AUTO_DELETE_VEC says whether the container (vector) should be deallocated.
  3982.    AUTO_DELETE say whether each item in the container should be deallocated.
  3983.  
  3984.    This also calls delete for virtual baseclasses of elements of the vector.
  3985.  
  3986.    Update: MAXINDEX is no longer needed.  The size can be extracted from the
  3987.    start of the vector for pointers, and from the type for arrays.  We still
  3988.    use MAXINDEX for arrays because it happens to already have one of the
  3989.    values we'd have to extract.  (We could use MAXINDEX with pointers to
  3990.    confirm the size, and trap if the numbers differ; not clear that it'd
  3991.    be worth bothering.)  */
  3992. tree
  3993. build_vec_delete (base, maxindex, elt_size, dtor_dummy, auto_delete_vec, auto_delete)
  3994.      tree base, maxindex, elt_size;
  3995.      tree dtor_dummy;
  3996.      tree auto_delete_vec, auto_delete;
  3997. {
  3998.   tree ptype = TREE_TYPE (base);
  3999.   tree type;
  4000.   tree virtual_size;
  4001.   /* Temporary variables used by the loop.  */
  4002.   tree tbase, size_exp, tbase_init;
  4003.  
  4004.   /* This is the body of the loop that implements the deletion of a
  4005.      single element, and moves temp variables to next elements.  */
  4006.   tree body;
  4007.  
  4008.   /* This is the LOOP_EXPR that governs the deletion of the elements.  */
  4009.   tree loop;
  4010.  
  4011.   /* This is the thing that governs what to do after the loop has run.  */
  4012.   tree deallocate_expr = 0;
  4013.  
  4014.   /* This is the BIND_EXPR which holds the outermost iterator of the
  4015.      loop.  It is convenient to set this variable up and test it before
  4016.      executing any other code in the loop.
  4017.      This is also the containing expression returned by this function.  */
  4018.   tree controller = NULL_TREE;
  4019.  
  4020.   /* This is the BLOCK to record the symbol binding for debugging.  */
  4021.   tree block;
  4022.  
  4023.   base = stabilize_reference (base);
  4024.  
  4025.   /* Since we can use base many times, save_epr it. */
  4026.   if (TREE_SIDE_EFFECTS (base))
  4027.     base = save_expr (base);
  4028.  
  4029.   if (TREE_CODE (ptype) == POINTER_TYPE)
  4030.     {
  4031.       /* Step back one from start of vector, and read dimension.  */
  4032.       tree cookie_addr = build (MINUS_EXPR, TYPE_POINTER_TO (BI_header_type),
  4033.                 base, BI_header_size);
  4034.       tree cookie = build_indirect_ref (cookie_addr, 0);
  4035.       maxindex = build_component_ref (cookie, get_identifier ("nelts"), 0, 0);
  4036.       do
  4037.     ptype = TREE_TYPE (ptype);
  4038.       while (TREE_CODE (ptype) == ARRAY_TYPE);
  4039.     }
  4040.   else if (TREE_CODE (ptype) == ARRAY_TYPE)
  4041.     {
  4042.       /* get the total number of things in the array, maxindex is a bad name */
  4043.       maxindex = array_type_nelts_total (ptype);
  4044.       while (TREE_CODE (ptype) == ARRAY_TYPE)
  4045.     ptype = TREE_TYPE (ptype);
  4046.       base = build_unary_op (ADDR_EXPR, base, 1);
  4047.     }
  4048.   else
  4049.     {
  4050.       error ("type to vector delete is neither pointer or array type");
  4051.       return error_mark_node;
  4052.     }
  4053.   type = ptype;
  4054.   ptype = TYPE_POINTER_TO (type);
  4055.  
  4056.   size_exp = size_in_bytes (type);
  4057.  
  4058.   if (! IS_AGGR_TYPE (type) || ! TYPE_NEEDS_DESTRUCTOR (type))
  4059.     {
  4060.       loop = integer_zero_node;
  4061.       goto no_destructor;
  4062.     }
  4063.  
  4064.   /* The below is short by BI_header_size */
  4065.   virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
  4066.  
  4067.   tbase = build_decl (VAR_DECL, NULL_TREE, ptype);
  4068.   tbase_init = build_modify_expr (tbase, NOP_EXPR,
  4069.                   fold (build (PLUS_EXPR, ptype,
  4070.                            base,
  4071.                            virtual_size)));
  4072.   DECL_REGISTER (tbase) = 1;
  4073.   controller = build (BIND_EXPR, void_type_node, tbase, 0, 0);
  4074.   TREE_SIDE_EFFECTS (controller) = 1;
  4075.   block = build_block (tbase, 0, 0, 0, 0);
  4076.   add_block_current_level (block);
  4077.  
  4078.   if (auto_delete != integer_zero_node
  4079.       && auto_delete != integer_two_node)
  4080.     {
  4081.       tree base_tbd = convert (ptype,
  4082.                    build_binary_op (MINUS_EXPR,
  4083.                         convert (ptr_type_node, base),
  4084.                         BI_header_size));
  4085.       /* This is the real size */
  4086.       virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
  4087.       body = build_tree_list (NULL_TREE,
  4088.                   build_x_delete (ptr_type_node, base_tbd, 0,
  4089.                           virtual_size));
  4090.       body = build (COND_EXPR, void_type_node,
  4091.             build (BIT_AND_EXPR, integer_type_node,
  4092.                auto_delete, integer_one_node),
  4093.             body, integer_zero_node);
  4094.     }
  4095.   else
  4096.     body = NULL_TREE;
  4097.  
  4098.   body = tree_cons (NULL_TREE,
  4099.             build_delete (ptype, tbase, auto_delete,
  4100.                   LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0, 0),
  4101.             body);
  4102.  
  4103.   body = tree_cons (NULL_TREE,
  4104.             build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
  4105.             body);
  4106.  
  4107.   body = tree_cons (NULL_TREE,
  4108.             build (EXIT_EXPR, void_type_node,
  4109.                build (EQ_EXPR, integer_type_node, base, tbase)),
  4110.             body);
  4111.  
  4112.   loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body));
  4113.  
  4114.   loop = tree_cons (NULL_TREE, tbase_init,
  4115.             tree_cons (NULL_TREE, loop, NULL_TREE));
  4116.   loop = build_compound_expr (loop);
  4117.  
  4118.  no_destructor:
  4119.   /* If the delete flag is one, or anything else with the low bit set,
  4120.      delete the storage.  */
  4121.   if (auto_delete_vec == integer_zero_node
  4122.       || auto_delete_vec == integer_two_node)
  4123.     deallocate_expr = integer_zero_node;
  4124.   else
  4125.     {
  4126.       tree base_tbd;
  4127.  
  4128.       /* The below is short by BI_header_size */
  4129.       virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
  4130.  
  4131.       if (loop == integer_zero_node)
  4132.     /* no header */
  4133.     base_tbd = base;
  4134.       else
  4135.     {
  4136.       base_tbd = convert (ptype,
  4137.                   build_binary_op (MINUS_EXPR,
  4138.                            convert (string_type_node, base),
  4139.                            BI_header_size));
  4140.       /* True size with header. */
  4141.       virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
  4142.     }
  4143.       deallocate_expr = build_x_delete (ptr_type_node, base_tbd, 1,
  4144.                     virtual_size);
  4145.       if (auto_delete_vec != integer_one_node)
  4146.     deallocate_expr = build (COND_EXPR, void_type_node,
  4147.                  build (BIT_AND_EXPR, integer_type_node,
  4148.                     auto_delete_vec, integer_one_node),
  4149.                  deallocate_expr, integer_zero_node);
  4150.     }
  4151.  
  4152.   if (loop && deallocate_expr != integer_zero_node)
  4153.     {
  4154.       body = tree_cons (NULL_TREE, loop,
  4155.             tree_cons (NULL_TREE, deallocate_expr, NULL_TREE));
  4156.       body = build_compound_expr (body);
  4157.     }
  4158.   else
  4159.     body = loop;
  4160.  
  4161.   /* Outermost wrapper: If pointer is null, punt.  */
  4162.   body = build (COND_EXPR, void_type_node,
  4163.         build (NE_EXPR, integer_type_node, base, integer_zero_node),
  4164.         body, integer_zero_node);
  4165.  
  4166.   if (controller)
  4167.     {
  4168.       TREE_OPERAND (controller, 1) = body;
  4169.       return controller;
  4170.     }
  4171.   else
  4172.     return convert (void_type_node, body);
  4173. }
  4174.